Skip to content

Commit

Permalink
cli: fix docstrings about config dir
Browse files Browse the repository at this point in the history
  • Loading branch information
Exirel committed Aug 31, 2019
1 parent 6b48ed4 commit f233c78
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
12 changes: 8 additions & 4 deletions sopel/cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,24 @@ def build_parser():


def handle_list(options):
"""Display a list of configuration available from Sopel's config directory
"""Display a list of configurations available in Sopel's config directory.
:param options: parsed arguments
:type options: ``argparse.Namespace``
This command displays an unordered list of config names from Sopel's
default config directory, without their extensions::
config directory, without their extensions::
$ sopel-config list
default
custom
It is possible to filter by extension using the ``-e``/``--ext``/``--extension``
option; default is ``.cfg`` (the ``.`` prefix is not required).
By default, the config directory is ``~/.sopel``. To select a different
config directory, options ``--config-dir`` can be used.
It is possible to filter by extension using the
``-e``/``--ext``/``--extension`` option; default is ``.cfg``
(the ``.`` prefix is not required).
"""
configdir = options.configdir
display_path = options.display_path
Expand Down
2 changes: 1 addition & 1 deletion sopel/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def print_version():


def print_config(configdir):
"""Print list of available configurations from default config directory."""
"""Print list of available configurations from config directory."""
configs = utils.enumerate_configs(configdir)
print('Config files in %s:' % configdir)
configfile = None
Expand Down
11 changes: 6 additions & 5 deletions sopel/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,11 @@ def load_settings(options):
.. note::
To use this function effectively, the
:func:`sopel.cli.utils.add_common_arguments` function should be used to
add the proper option to the argument parser.
This function expects that ``options`` exposes two attributes:
``config`` and ``configdir``.
The :func:`sopel.cli.utils.add_common_arguments` function should be
used to add these options to the argument parser.
"""
# Default if no options.config or no env var or if they are empty
Expand All @@ -328,8 +330,7 @@ def load_settings(options):
elif 'SOPEL_CONFIG' in os.environ:
name = os.environ['SOPEL_CONFIG'] or name # use default if empty

filename = find_config(
getattr(options, 'configdir', config.DEFAULT_HOMEDIR), name)
filename = find_config(options.configdir, name)

if not os.path.isfile(filename):
raise config.ConfigurationNotFound(filename=filename)
Expand Down
5 changes: 4 additions & 1 deletion test/cli/test_cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ def test_add_common_arguments():


def test_add_common_arguments_subparser():
"""Assert function adds the -c/--config option on a subparser."""
"""Assert function adds the multiple options on a subparser.
The expected options are -c/--config and --config-dir.
"""
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest='action')
sub = subparsers.add_parser('sub')
Expand Down

0 comments on commit f233c78

Please sign in to comment.