Add support for configuration files

Configuration files allow common arguments like --shadowy-level and
--blacklist to be saved and referenced rather being typed out each time.

ArgumentParser has been subclassed to allow more freedom when parsing
configuration files.
This commit is contained in:
Jeremy Saklad 2021-08-13 10:26:59 -05:00
parent be44c9c489
commit 4034530ddb
Signed by: Jeremy Saklad
GPG Key ID: 9CA2149583EDBF84
3 changed files with 22 additions and 1 deletions

View File

@ -54,6 +54,16 @@ You may wish to blacklist options that:
* add Exhaustion * add Exhaustion
* you simply don't have a good source for * you simply don't have a good source for
### Configuration Files
Rather than typing out every argument each time you use the solver, you may provide a file path (prefixed with "@") to the CLI.
This file should contain command-line arguments. The solver will interpret these arguments as if they were typed in place of the file path.
Configuration files are read top-to-bottom. Arguments can be delimited by a single space, broken onto different lines, or any combination thereof.
Any number of configuration files may be provided simultaneously.
## Caveats ## Caveats
The solver aims to maximize profit margin, rather than sheer profit. This is because it may be more profitable to make many smaller skeletons than one massive skeleton. The solver aims to maximize profit margin, rather than sheer profit. This is because it may be more profitable to make many smaller skeletons than one massive skeleton.

View File

@ -2,12 +2,14 @@ import argparse
import curses import curses
from .objects.blacklistaction import BlacklistAction from .objects.blacklistaction import BlacklistAction
from .objects.bonemarketargumentparser import BoneMarketArgumentParser
from .objects.enumaction import EnumAction from .objects.enumaction import EnumAction
from .solve import * from .solve import *
parser = argparse.ArgumentParser( parser = BoneMarketArgumentParser(
prog='Bone Market Solver', prog='Bone Market Solver',
description="Devise the optimal skeleton at the Bone Market in Fallen London.", description="Devise the optimal skeleton at the Bone Market in Fallen London.",
fromfile_prefix_chars="@",
argument_default=argparse.SUPPRESS, argument_default=argparse.SUPPRESS,
) )

View File

@ -0,0 +1,9 @@
__all__ = ['BoneMarketArgumentParser']
__author__ = "Jeremy Saklad"
from argparse import ArgumentParser
class BoneMarketArgumentParser(ArgumentParser):
"""An ArgumentParser with the ability to read files with any number of space-delimited arguments on a line."""
def convert_arg_line_to_args(self, arg_line):
return arg_line.split()