Metadata-Version: 2.1
Name: dcflags
Version: 0.2.1
Summary: Dataclass fields as cmd args and env vars
Home-page: https://github.com/adriansahlman/dcflags
Author: Adrian Sahlman
Author-email: adrian.sahlman@gmail.com
License: MIT
Keywords: parse arguments cmd command dataclass env environmental dcflags
Requires-Python: >=3.5
Description-Content-Type: text/markdown
License-File: LICENSE

# dcflags

Python package for initializing a dataclass with arguments from the command line or values from environmental variables.
Meant to work as an entrypoint for applications, nothing else.

## Install

dcflags is available through pip
```shell
pip install dcflags
```

## Usage
```python
# main.py

import dataclasses
import dcflags


@dataclasses.dataclass
class Config:
    output: str
    workers: int = 1
    verbose: bool = False


if __name__ == "__main__":
    cfg = dcflags.parse(Config)
    print(cfg)
```
```
# help message
$ python main.py --help
usage: main.py [-h] [--output OUTPUT] [--workers WORKERS] [--verbose [VERBOSE]]

options:
  -h, --help           show this help message and exit
  --output OUTPUT      type: str, env: $OUTPUT
  --workers WORKERS    type: int, env: $WORKERS, default: 1
  --verbose [VERBOSE]  type: bool, env: $VERBOSE, default: False

# missing required argument
$ python main.py
usage: main.py [-h] [--output OUTPUT] [--workers WORKERS] [--verbose [VERBOSE]]
main.py: error: the following arguments are required: --output/$OUTPUT

# command line arguments
$ python main.py --output=file.txt
Config(output='file.txt', workers=1, verbose=False)

# env vars
$ OUTPUT=test.txt python main.py
Config(output='test.txt', workers=1, verbose=False)

# a bit of everything
$ OUTPUT=new.txt python main.py --verbose --workers=3
Config(output='new.txt', workers=3, verbose=True)
```
