-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* doc strings according to PEP * skipped tests marked properly * refactored CLI * added autocompletion * cleanup * switch github actions from checkout@v1 to checkout@v2 * fixed codecov name in github actions
- Loading branch information
1 parent
ba0695c
commit d1b8155
Showing
28 changed files
with
321 additions
and
227 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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import sys | ||
|
||
from nichtparasoup.cmdline import main | ||
from nichtparasoup.cli.main import main as _main | ||
|
||
sys.exit(main()) | ||
sys.exit(_main()) |
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,4 @@ | ||
"""Subpackage containing all of nichtparasoup's command line interface related code | ||
""" | ||
|
||
# This file intentionally does not import submodules |
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,24 @@ | ||
# PYTHON_ARGCOMPLETE_OK | ||
|
||
__all__ = ["main"] | ||
|
||
import logging | ||
from typing import List, Optional | ||
|
||
from argcomplete import autocomplete # type: ignore | ||
|
||
from nichtparasoup._internals import _logging_init, _message | ||
from nichtparasoup.cli.commands import Commands | ||
from nichtparasoup.cli.parser import create_parser | ||
|
||
|
||
def main(args: Optional[List[str]] = None) -> int: # pragma: no cover | ||
parser = create_parser() | ||
autocomplete(parser, always_complete_options='long') | ||
options = dict(parser.parse_args(args=args).__dict__) | ||
del parser | ||
if options.pop('debug', False): | ||
_logging_init(logging.DEBUG) | ||
_message('DEBUG ENABLED :)', 'cyan') | ||
command = options.pop('command') | ||
return getattr(Commands, command)(**options) # type: ignore |
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,120 @@ | ||
__all__ = ["create_parser"] | ||
|
||
from argparse import ArgumentParser | ||
from typing import Any, Set | ||
|
||
from argcomplete import FilesCompleter # type: ignore | ||
|
||
from nichtparasoup.imagecrawler import get_imagecrawlers | ||
|
||
|
||
def imagecrawler_completion(*args: Any, **kwargs: Any) -> Set[str]: | ||
return set(get_imagecrawlers().names()) | ||
|
||
|
||
yaml_file_completion = FilesCompleter('yaml', 'yml') | ||
|
||
|
||
def create_parser() -> ArgumentParser: # pragma: no cover | ||
# used `__tmp_action` several times, to omit type-checkers warning ala 'Action has no attribute "completer"' | ||
|
||
parser = ArgumentParser( | ||
add_help=True, | ||
allow_abbrev=False, | ||
) | ||
|
||
parser.add_argument( | ||
'--debug', | ||
help='Enable debug output.', | ||
action='store_true', dest="debug", | ||
) | ||
|
||
commands = parser.add_subparsers( | ||
title='Commands', | ||
metavar='<command>', | ||
dest='command', | ||
) | ||
commands.required = True | ||
|
||
command_run = commands.add_parser( | ||
'run', | ||
help='run a server', | ||
description='Start a web-server to display random images.', | ||
add_help=True, | ||
allow_abbrev=False, | ||
) | ||
__tmp_action = command_run.add_argument( | ||
'-c', '--use-config', | ||
help='Use a YAML config file instead of the defaults.', | ||
metavar='<file>', | ||
action='store', dest="config_file", type=str, | ||
) | ||
__tmp_action.completer = yaml_file_completion # type: ignore | ||
del __tmp_action | ||
|
||
command_config = commands.add_parser( | ||
'config', | ||
description='Get config related things done.', | ||
help='Config related functions.', | ||
add_help=True, | ||
allow_abbrev=False, | ||
) | ||
command_config_switches = command_config.add_mutually_exclusive_group(required=True) | ||
__tmp_action = command_config_switches.add_argument( | ||
'--check', | ||
help='Validate and probe a YAML config file;', | ||
metavar='<file>', | ||
action='store', dest='check', type=str, | ||
) | ||
__tmp_action.completer = yaml_file_completion # type: ignore | ||
del __tmp_action | ||
command_config_switches.add_argument( | ||
'--dump', | ||
help='Dump YAML config into a file;', | ||
metavar='<file>', | ||
action='store', dest='dump', type=str, | ||
) | ||
|
||
command_info = commands.add_parser( | ||
'info', | ||
description='Get info for several topics.', | ||
help='Get info for several topics.', | ||
add_help=True, | ||
allow_abbrev=False, | ||
) | ||
command_info_switches = command_info.add_mutually_exclusive_group(required=True) | ||
command_info_switches.add_argument( | ||
'--imagecrawler-list', | ||
help='List available image crawler types.', | ||
action='store_true', dest='imagecrawler_list', | ||
) | ||
__tmp_action = command_info_switches.add_argument( | ||
'--imagecrawler-desc', | ||
help='Describe an image crawler type and its config.', | ||
metavar='<crawler>', | ||
action='store', dest='imagecrawler_desc', type=str, | ||
) | ||
__tmp_action.completer = imagecrawler_completion # type: ignore | ||
del __tmp_action | ||
command_info_switches.add_argument( | ||
'--version', | ||
help="Show program's version number.", | ||
action='store_true', dest='version', | ||
) | ||
|
||
command_completion = commands.add_parser( | ||
'completion', | ||
description='Helper command used for command completion.', | ||
epilog='Autocompletion is powered by https://pypi.org/project/argcomplete/', | ||
help='Helper command to be used for command completion.', | ||
add_help=True, | ||
allow_abbrev=False, | ||
) | ||
command_completion.add_argument( | ||
'-s', '--shell', | ||
help='Emit completion code for the specified shell.', | ||
action='store', dest='shell', type=str, required=True, | ||
choices=('bash', 'tcsh', 'fish'), | ||
) | ||
|
||
return parser |
Oops, something went wrong.