From 4034530ddb915c8ae247a5984ece6f1c3186bf53 Mon Sep 17 00:00:00 2001 From: Jeremy Saklad Date: Fri, 13 Aug 2021 10:26:59 -0500 Subject: [PATCH] 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. --- README.md | 10 ++++++++++ bonemarketsolver/__main__.py | 4 +++- bonemarketsolver/objects/bonemarketargumentparser.py | 9 +++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 bonemarketsolver/objects/bonemarketargumentparser.py diff --git a/README.md b/README.md index 11adac5..0084d2a 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,16 @@ You may wish to blacklist options that: * add Exhaustion * 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 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. diff --git a/bonemarketsolver/__main__.py b/bonemarketsolver/__main__.py index d00f5d8..386334d 100644 --- a/bonemarketsolver/__main__.py +++ b/bonemarketsolver/__main__.py @@ -2,12 +2,14 @@ import argparse import curses from .objects.blacklistaction import BlacklistAction +from .objects.bonemarketargumentparser import BoneMarketArgumentParser from .objects.enumaction import EnumAction from .solve import * -parser = argparse.ArgumentParser( +parser = BoneMarketArgumentParser( prog='Bone Market Solver', description="Devise the optimal skeleton at the Bone Market in Fallen London.", + fromfile_prefix_chars="@", argument_default=argparse.SUPPRESS, ) diff --git a/bonemarketsolver/objects/bonemarketargumentparser.py b/bonemarketsolver/objects/bonemarketargumentparser.py new file mode 100644 index 0000000..196b196 --- /dev/null +++ b/bonemarketsolver/objects/bonemarketargumentparser.py @@ -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()