Skip to content
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

support CLI arguments via config file #105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/docto.config

__pycache__
*.pyc

Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,25 @@ Further optional arguments:
--code CODE 2FA code
```

For easier reuse, it is possible to provide the arguments in a config file containing each parameter in a separate line.

```
./doctoshotgun.py @filename
```

> Beware: argument name and value need to go to separate lines, values have no quotes

Example `docto.config`:
```
fr
paris
[email protected]
--center
Centre de Vaccination Covid 19 - Ville de Paris
--center
Centre de Vaccination du 7eme arrondissement de Paris - Gymnase Camou
```

### With Docker

Build the image:
Expand Down
3 changes: 2 additions & 1 deletion doctoshotgun.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,8 @@ def main(self, cli_args=None):
}

parser = argparse.ArgumentParser(
description="Book a vaccine slot on Doctolib")
description="Book a vaccine slot on Doctolib",
fromfile_prefix_chars='@')
parser.add_argument('--debug', '-d', action='store_true',
help='show debug information')
parser.add_argument('--pfizer', '-z', action='store_true',
Expand Down
24 changes: 24 additions & 0 deletions test_cli_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,23 @@ def test_center_exclude_arg_should_filter_excluded_centers(MockDoctolibDE, tmp_p
assert call_args_list.args[0]['city'] == city


@responses.activate
@patch('doctoshotgun.DoctolibDE')
def test_config_file_should_be_used(MockDoctolibDE, tmp_path):
"""
Check that config file is used corrrectly
"""
# prepare
mock_doctolib_de = get_mocked_doctolib(MockDoctolibDE)

# call
call_application_without_default_args(
cli_args=['@test_fixtures/docto.config'])

# assert
assert mock_doctolib_de.try_to_book.called


def get_mocked_doctolib(MockDoctolibDE):
mock_doctolib_de = MagicMock(wraps=DoctolibDE)
MockDoctolibDE.return_value = mock_doctolib_de
Expand All @@ -89,3 +106,10 @@ def call_application(city, cli_args=[]):
Application(),
cli_args=["de", city, "[email protected]", "1234"] + cli_args
)


def call_application_without_default_args(cli_args):
assert 0 == Application.main(
Application(),
cli_args=cli_args
)
4 changes: 4 additions & 0 deletions test_fixtures/docto.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
de
koln
[email protected]
1234