Skip to content

Commit

Permalink
MILC: Use dashes instead of underscores for subcommands
Browse files Browse the repository at this point in the history
The subcommand functions' name follows the Python convention of using
snake case, but looks odd on the command line.
Fix it by converting underscores to dashes, eg.: list_keyboards ->
list-keyboards.
  • Loading branch information
Erovia authored and fdidron committed Nov 4, 2019
1 parent 415ab3c commit e3e2489
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/python/milc.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,12 @@ def argument_function(handler):
self.arg_only.append(arg_name)
del kwargs['arg_only']

name = handler.__name__.replace("_", "-")
if handler is self._entrypoint:
self.add_argument(*args, **kwargs)

elif handler.__name__ in self.subcommands:
self.subcommands[handler.__name__].add_argument(*args, **kwargs)
elif name in self.subcommands:
self.subcommands[name].add_argument(*args, **kwargs)

else:
raise RuntimeError('Decorated function is not entrypoint or subcommand!')
Expand Down Expand Up @@ -599,7 +600,7 @@ def add_subcommand(self, handler, description, name=None, **kwargs):
self.add_subparsers()

if not name:
name = handler.__name__
name = handler.__name__.replace("_", "-")

self.acquire_lock()
kwargs['help'] = description
Expand Down
2 changes: 1 addition & 1 deletion lib/python/qmk/tests/test_cli_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_pyformat():


def test_list_keyboards():
result = check_subcommand('list_keyboards')
result = check_subcommand('list-keyboards')
assert result.returncode == 0
# check to see if a known keyboard is returned
# this will fail if handwired/onekey/pytest is removed
Expand Down

0 comments on commit e3e2489

Please sign in to comment.