Skip to content

Commit

Permalink
cli: rename add_config_argument to *_common_*
Browse files Browse the repository at this point in the history
  • Loading branch information
Exirel committed Feb 15, 2019
1 parent ec37be9 commit 2bf5e05
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion sopel/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Shortcut imports
from .utils import ( # noqa
add_config_arguments,
add_common_arguments,
enumerate_configs,
find_config,
load_settings
Expand Down
20 changes: 13 additions & 7 deletions sopel/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
__all__ = [
'enumerate_configs',
'find_config',
'add_config_arguments',
'add_common_arguments',
'load_settings',
]

Expand Down Expand Up @@ -84,15 +84,15 @@ def find_config(config_dir, name, extension='.cfg'):
return os.path.join(config_dir, name)


def add_config_arguments(parser):
"""Add configuration-related argument to a ``parser``.
def add_common_arguments(parser):
"""Add common and configuration-related arguments to a ``parser``.
:param parser: Argument parser (or subparser)
:type parser: argparse.ArgumentParser
This function adds the proper argument to the ``parser`` given in order to
have a standard way to define a configuration filename in all of Sopel's
command line interfaces.
This functions adds the common arguments for Sopel's command line tools.
At the moment, this functions adds only one argument to the parser: the
argument used as the standard way to define a configuration filename.
This can be used on an argument parser, or an argument subparser, to handle
these cases::
Expand All @@ -102,6 +102,12 @@ def add_config_arguments(parser):
Then, when the parser parses the command line arguments, it will expose
a ``config`` option to be used to find and load Sopel's settings.
.. seealso::
The :func:`sopel.cli.utils.load_settings` function uses an ``options``
object from a parser configured with such arguments.
"""
parser.add_argument(
'-c', '--config',
Expand Down Expand Up @@ -136,7 +142,7 @@ def load_settings(options):
.. note::
To use this function effectively, the
:func:`sopel.cli.utils.add_config_arguments` function should be used to
:func:`sopel.cli.utils.add_common_arguments` function should be used to
add the proper option to the argument parser.
"""
Expand Down
2 changes: 1 addition & 1 deletion sopel/run_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def build_parser():
"""Build an ``argparse.ArgumentParser`` for the bot"""
parser = argparse.ArgumentParser(description='Sopel IRC Bot',
usage='%(prog)s [options]')
utils.add_config_arguments(parser)
utils.add_common_arguments(parser)
parser.add_argument("-d", '--fork', action="store_true",
dest="daemonize", help="Daemonize Sopel")
parser.add_argument("-q", '--quit', action="store_true", dest="quit",
Expand Down
10 changes: 5 additions & 5 deletions test/cli/test_cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import pytest

from sopel.cli.utils import enumerate_configs, find_config, add_config_arguments
from sopel.cli.utils import enumerate_configs, find_config, add_common_arguments


@contextmanager
Expand Down Expand Up @@ -92,10 +92,10 @@ def test_find_config_extension(tmpdir, config_dir):
assert found_config == config_dir.join('extra.ini').strpath


def test_add_config_arguments():
def test_add_common_arguments():
"""Assert function adds the -c/--config option."""
parser = argparse.ArgumentParser()
add_config_arguments(parser)
add_common_arguments(parser)

options = parser.parse_args([])
assert hasattr(options, 'config')
Expand All @@ -108,12 +108,12 @@ def test_add_config_arguments():
assert options.config == 'test-long'


def test_add_config_arguments_subparser():
def test_add_common_arguments_subparser():
"""Assert function adds the -c/--config option on a subparser."""
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest='action')
sub = subparsers.add_parser('sub')
add_config_arguments(sub)
add_common_arguments(sub)

options = parser.parse_args(['sub'])
assert hasattr(options, 'config')
Expand Down

0 comments on commit 2bf5e05

Please sign in to comment.