-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Config utilities for describing config files and CLI arguments #17
Conversation
Having a common base class allows users to catch all xylem related exceptions in one handler.
- extensive tests for config types - tests for other parts of config utils are still TODO
- new module `config` describes the global configuration - `config` includes the logic to compute soruces and cache folders given command line arguments and options - `arguments` module features help action, which uses pydoc.pager to display the help in a `less`-like scrollable manner on pty's - help output includes new section `config arguments`, describing the arguments that correspond to a config file entry - commands have a new hook to add to the config description; some logic common to all commands was moved to `commands.main` - context objects like `InstallerContext` and `SourcesContext` now take a config dictionary as argument, which defaults to the global config sigleton if not passed explicitly - high-level API used by the commands (`update`, `resolve`, `lookup`) is also parameterized by an optional config dict argument, which defaults to the global config
@wjwwood please review. This has become a bit more extensive than anticipated. More stuff to follow soon. |
@NikolausDemmel Extensive indeed, I'll do my best to review it tonight. |
# add argument groups and some global config-related arguments that | ||
# are independent from the description | ||
group = parser.add_argument_group('global arguments') | ||
add_global_config_arguments(group, "footool") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this also use TOOL_NAME
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
I'm not sure if this is desired, but I get this when using the
|
When I run
|
Ok, other than the few small comments this is a +1 from me. Please fixup those things I touched on, merge this, and then rebase the other pull requests. |
It seems to be a limitation of argparse to not allow optional subparsers. The simplest fix might involve http://stackoverflow.com/a/22054398/1813258. P.S.: I just stumbled upon http://docopt.org/ (the recorded talk is a nice watch). I seems like a really powerful and simple way to do CLI, but unfortunately it looks to be not as practical when options come from different places.
Will fix. |
Config utilities for describing config files and CLI arguments - new module `config_utils` for a general purpose tool to describe config files, parse yaml config files and expose specific arguments to the command line; includes some unit tests for the config item types - new module `config` describes xylem's global configuration; includes the logic to compute sources and cache folders given command line arguments and config files - new module `arguments` for global command line arguments (moved from `utils`); interacts with config to include and process global config arguments - new module `yaml_utils` contains customization to loading and dumping yaml (moved (from `utils`) - `--help` argument now uses pydoc.pager to display the help in a `less`-like scrollable manner on pty's - help output includes new section `config arguments`, describing the arguments that correspond to a config file entry - commands have a new hook to add to the config description; some logic common to all commands was moved to `commands.main` - context objects like `InstallerContext` and `SourcesContext` now take a config dictionary as argument, which defaults to the global config singleton if not passed explicitly - high-level API used by the commands (`update`, `resolve`, `lookup`) is also parameterized by an optional config dict argument, which defaults to the global config - Introduce XylemError as common Exception base class. Having a common base class allows users to catch all xylem related exceptions in one handler.
I addressed the other comments as a new commit 720d3db ontop of the most recent stuff to avoid rebasing so many commits and possibly manually mergin a bunch of times. Thanks for the comments. |
config_utils
for a general purpose tool to describe config files, parseyaml config files and expose specific arguments to the command line; includes some
unit tests for the config item types
config
describes xylem's global configuration; includes the logic tocompute sources and cache folders given command line arguments and config files
arguments
for global command line arguments (moved fromutils
);interacts with config to include and process global config arguments
yaml_utils
contains customization to loading and dumping yaml (moved(from
utils
)--help
argument now uses pydoc.pager to display the help in aless
-like scrollablemanner on pty's
config arguments
, describing the argumentsthat correspond to a config file entry
to all commands was moved to
commands.main
InstallerContext
andSourcesContext
now take a configdictionary as argument, which defaults to the global config singleton if not
passed explicitly
update
,resolve
,lookup
) is alsoparameterized by an optional config dict argument, which defaults to the
global config
base class allows users to catch all xylem related exceptions in one handler.
Output of
xylem resolve --help
:Given the following config file in
~/.config/xylem/config.yaml
,the output of two example commands to illustrate the config functionality follows: