Add list option
This option lists enumeration identifiers, along with their string forms for clarity's sake. This makes it much easier to blacklist things without reading the source code. A note about listing has been added to the Blacklisting section of the README. A dedicated action has been created for the list command.
This commit is contained in:
parent
3b1ca61104
commit
35663dd8d4
@ -55,6 +55,12 @@ You may wish to blacklist options that:
|
||||
* add Exhaustion
|
||||
* you simply don't have a good source for
|
||||
|
||||
To get a list of identifiers, use:
|
||||
```sh
|
||||
pipenv run bone_market_solver --list
|
||||
```
|
||||
Specific enumerations may be provided to narrow what is shown.
|
||||
|
||||
### 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.
|
||||
|
@ -4,6 +4,7 @@ import curses
|
||||
from .objects.blacklistaction import BlacklistAction
|
||||
from .objects.bonemarketargumentparser import BoneMarketArgumentParser
|
||||
from .objects.enumaction import EnumAction
|
||||
from .objects.listaction import ListAction
|
||||
from .solve import *
|
||||
|
||||
parser = BoneMarketArgumentParser(
|
||||
@ -13,6 +14,16 @@ parser = BoneMarketArgumentParser(
|
||||
argument_default=argparse.SUPPRESS,
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-l", "--list",
|
||||
action=ListAction,
|
||||
default=ListAction.list_options,
|
||||
choices=ListAction.list_options,
|
||||
nargs=argparse.ZERO_OR_MORE,
|
||||
help="list specified enumerations and their names and exit",
|
||||
dest=argparse.SUPPRESS
|
||||
)
|
||||
|
||||
|
||||
world_qualities = parser.add_argument_group(
|
||||
"world qualities",
|
||||
|
53
bonemarketsolver/objects/listaction.py
Normal file
53
bonemarketsolver/objects/listaction.py
Normal file
@ -0,0 +1,53 @@
|
||||
__all__ = ['ListAction']
|
||||
__author__ = "Jeremy Saklad"
|
||||
|
||||
import argparse
|
||||
from functools import reduce
|
||||
|
||||
from ..data.adjustments import Adjustment
|
||||
from ..data.appendages import Appendage
|
||||
from ..data.buyers import Buyer
|
||||
from ..data.declarations import Declaration
|
||||
from ..data.embellishments import Embellishment
|
||||
from ..data.skulls import Skull
|
||||
from ..data.torsos import Torso
|
||||
|
||||
class ListAction(argparse.Action):
|
||||
"""Lists enumerations referenced by provided strings then exits"""
|
||||
|
||||
list_options = [enum.__name__.lower() for enum in [
|
||||
Torso,
|
||||
Skull,
|
||||
Appendage,
|
||||
Adjustment,
|
||||
Declaration,
|
||||
Embellishment,
|
||||
Buyer,
|
||||
]]
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
nargs = kwargs.get('nargs')
|
||||
default = kwargs.get('default')
|
||||
|
||||
super(ListAction, self).__init__(**kwargs)
|
||||
|
||||
self._nargs = nargs
|
||||
self._default = default
|
||||
|
||||
@staticmethod
|
||||
def printable_list(enum):
|
||||
def printable_item(member):
|
||||
return f"\n\t{enum.__name__}.{member.name}:\n\t\t{member}"
|
||||
|
||||
return "{}:{}".format(enum.__name__, str().join([printable_item(member) for member in enum]))
|
||||
|
||||
def __call__(self, parser, namespace, values, option_string=None):
|
||||
# Check whether this is a single value or a list of them
|
||||
if self._nargs is None or self._nargs == argparse.OPTIONAL:
|
||||
# Convert value into an Enum type and print
|
||||
print(self.printable_list(globals()[values.capitalize()]))
|
||||
else:
|
||||
# Convert values back into Enum types and print
|
||||
print(*[self.printable_list(globals()[value.capitalize()]) for value in (values if values else self._default)], sep="\n\n")
|
||||
|
||||
parser.exit()
|
Loading…
Reference in New Issue
Block a user