-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated docs with better cmd-line info (#72)
- Loading branch information
Showing
6 changed files
with
103 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Drop In Replacement For Argparser | ||
|
||
`spock` can easily be used as a drop in for argparser. This means that all parameter definitions as required to come in | ||
from the command line or from setting defaults within the `@spock` decorated classes. | ||
|
||
### Automatic Command-Line Argument Generation | ||
|
||
`spock` will automatically generate command line arguments for each parameter, unless the `no_cmd_line=True` flag is | ||
passed to the `ConfigArgBuilder`. Let's create a simple example to demonstrate: | ||
|
||
```python | ||
from spock.config import spock | ||
from typing import Optional | ||
|
||
@spock | ||
class ExampleConfig: | ||
read_path: str = '/tmp' | ||
date: int | ||
cache_path: Optional[str] | ||
``` | ||
|
||
Given these definitions, `spock` will automatically generate a command-line argument (via an internally maintained | ||
argparser) for each parameter within each `@spock` decorated class. The syntax follows simple dot notation | ||
of `--classname.parameter`. Thus, for our sample classes above, `spock` will automatically generate the following | ||
valid command-line arguments: | ||
|
||
```shell | ||
--ExampleConfig.read_path *value* | ||
--ExampleConfig.date *value* | ||
--ExampleConfig.cache_path *value* | ||
``` | ||
|
||
### Use Spock via the Command-Line | ||
|
||
Simply do not pass a `-c` or `--config` argument at the command line and instead pass in all values to the | ||
automatically generated cmd-line arguments. | ||
|
||
```bash | ||
$ python simple.py --ExampleConfig.read_path /my/file/path --ExampleConfig.date 1292838124 \ | ||
--ExampleConfig.cache_path /path/to/cache/dir | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters