Return section option keys in config cli when option is missing.
@@ -18,7 +18,7 @@ def setup_parser(sub_parsers):
Config.instance().config_file))
parser.add_argument("name", nargs="?", help="the name of the config in the format"
- " <section>.<option>")
+ " <section>[.<option>]")
parser.add_argument("value", nargs="?", help="the value to set")
parser.add_argument("--remove", "-r", action="store_true", help="remove the config")
parser.add_argument("--expand", "-e", action="store_true", help="expand variables when getting"
@@ -38,7 +38,7 @@ def execute(args):
# every option below requires the name to be set
if not args.name:
- abort("please give the name of the config in the format <section>.<option>")
+ abort("please give the name of the config in the format <section>[.<option>]")
# removal
if args.remove:
@@ -55,10 +55,17 @@ def execute(args):
def get_config(name, expand=False):
"""
Returns the config value that corresponds to *name*, which must have the format
- ``section.option``.
+ ``<section>[.<option>]``. When an option is given and *expand* is *True*, variables are expanded
+ in the returned value.
"""
cfg = Config.instance()
- func = cfg.get_expanded if expand else cfg.get
+ only_section = "." not in name
+
+ # when only the section is given, print all keys
+ if only_section:
+ return "\n".join(cfg.keys(name))
+ else:
section, option = name.split(".", 1)
+ func = cfg.get_expanded if expand else cfg.get
return func(section, option)
