Merge lp:~jtv/maas/maascli-cli-subcommand into lp:maas/trunk

Proposed by Jeroen T. Vermeulen on 2012-10-08
Status: Rejected
Rejected by: Jeroen T. Vermeulen on 2012-11-01
Proposed branch: lp:~jtv/maas/maascli-cli-subcommand
Merge into: lp:maas/trunk
Diff against target: 67 lines (+9/-6)
3 files modified
src/maascli/cli.py (+6/-4)
src/maascli/tests/test_cli.py (+2/-1)
src/maascli/tests/test_integration.py (+1/-1)
To merge this branch: bzr merge lp:~jtv/maas/maascli-cli-subcommand
Reviewer Review Type Date Requested Status
Gavin Panella (community) 2012-10-08 Needs Information on 2012-10-08
Review via email: mp+128538@code.launchpad.net

Commit Message

Move maascli's CLI management commands (login, list etc.) into a dedicated sub-command "cli."

Description of the Change

This was pre-imped ages ago, I think several times actually. It seems like a complication to say "maascli cli list" instead of just "maascli list," and so on, but after this I'll be able to make maascli pick a default profile, and move the current profile's API operations directly into the main namespace. So in return for this extra work, you'll be able to type API verbs directly after the "maascli" command.

Jeroen

To post a comment you must log in.
lp:~jtv/maas/maascli-cli-subcommand updated on 2012-10-08
1226. By Jeroen T. Vermeulen on 2012-10-08

Fix some arbitrary typos to trigger a re-diff on the MP.

Gavin Panella (allenap) wrote :

> This was pre-imped ages ago, I think several times actually. It
> seems like a complication to say "maascli cli list" instead of just
> "maascli list," and so on, but after this I'll be able to make
> maascli pick a default profile, and move the current profile's API
> operations directly into the main namespace. So in return for this
> extra work, you'll be able to type API verbs directly after the
> "maascli" command.

I've made my thoughts clear ad nauseam, that I think having a default
profile is a retrograde step, but the code looks just fine :)

I'm actually having second thoughts about this change though. A new
user is going to be faced with:

  $ bin/maascli --help
  usage: bin/maascli [-h] COMMAND ...

  optional arguments:
    -h, --help  show this help message and exit

  drill down:
    COMMAND
      cli       CLI management commands

  http://maas.ubuntu.com/

It's not very obvious what to do now - just like it wasn't when we had
the "api" command - and that's at odds with the desire to make things
easier for the newbie, for which the default profile is intended (and
exceedingly lazy typists).

I'm not going to reject this, but I do think this is a step too far,
and needs a second opinion.

review: Needs Information
Raphaël Badin (rvb) wrote :

I agree with Gavin that putting login/logout/etc. under the 'cli' sub command will be a bit weird from a user's perspective.

I'm trying to think, step by step, what a user would do when he first interacts with the CLI and make sure that, at each step, what to do next is clear. As Gavin pointed out, the first step won't be obvious if the commands are "hidden" inside the 'cpi' subcommand. How about renaming login/logout/list/etc into maas_login/maas_logout/maas_list/maas_etc? This way, we avoid clashing with API commands and we still show the important commands when 'bin/maascli --help' is run from the first time.

What do you say?

Jeroen T. Vermeulen (jtv) wrote :

I would think that the right thing to do is point out the need for a login in the help text. I've already got some of that further up in my branch pipeline.

Once you're logged in, if there's a default profile, its API commands appear directly in the --help output.

Jeroen T. Vermeulen (jtv) wrote :

Scuttling this. We may or may not come back to it later, but for now we found the CLI tolerable with the improvements already made. Also, the “default profile” approach that this branch works towards is still controversial.

Unmerged revisions

1226. By Jeroen T. Vermeulen on 2012-10-08

Fix some arbitrary typos to trigger a re-diff on the MP.

1225. By Jeroen T. Vermeulen on 2012-10-08

Move cli commands out of maascli's main namespace.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maascli/cli.py'
2--- src/maascli/cli.py 2012-10-08 13:39:12 +0000
3+++ src/maascli/cli.py 2012-10-08 16:37:21 +0000
4@@ -27,7 +27,7 @@
5
6
7 class cmd_login(Command):
8- """Log-in to a remote API, storing its description and credentials.
9+ """Log in to a remote API, storing its description and credentials.
10
11 If credentials are not provided on the command-line, they will be prompted
12 for interactively.
13@@ -88,7 +88,7 @@
14
15
16 class cmd_logout(Command):
17- """Log-out of a remote API, purging any stored credentials."""
18+ """Log out of a remote API, purging any stored credentials."""
19
20 def __init__(self, parser):
21 super(cmd_logout, self).__init__(parser)
22@@ -104,7 +104,7 @@
23
24
25 class cmd_list(Command):
26- """List remote APIs that have been logged-in to."""
27+ """List remote APIs that have been logged in to."""
28
29 def __call__(self, options):
30 with ProfileConfig.open() as config:
31@@ -129,8 +129,10 @@
32
33 def register_cli_commands(parser):
34 """Register the CLI's meta-subcommands on `parser`."""
35+ cli_parser = parser.subparsers.add_parser(
36+ 'cli', help="CLI management commands")
37 for name, command in commands.items():
38 help_title, help_body = parse_docstring(command)
39- command_parser = parser.subparsers.add_parser(
40+ command_parser = cli_parser.subparsers.add_parser(
41 safe_name(name), help=help_title, description=help_body)
42 command_parser.set_defaults(execute=command(command_parser))
43
44=== modified file 'src/maascli/tests/test_cli.py'
45--- src/maascli/tests/test_cli.py 2012-10-08 14:13:24 +0000
46+++ src/maascli/tests/test_cli.py 2012-10-08 16:37:21 +0000
47@@ -29,6 +29,7 @@
48 def test_subparsers_have_appropriate_execute_defaults(self):
49 parser = ArgumentParser()
50 cli.register_cli_commands(parser)
51+ cli_parser = parser.subparsers.choices['cli']
52 self.assertIsInstance(
53- parser.subparsers.choices['login'].get_default('execute'),
54+ cli_parser.subparsers.choices['login'].get_default('execute'),
55 cli.cmd_login)
56
57=== modified file 'src/maascli/tests/test_integration.py'
58--- src/maascli/tests/test_integration.py 2012-10-04 08:36:34 +0000
59+++ src/maascli/tests/test_integration.py 2012-10-08 16:37:21 +0000
60@@ -48,6 +48,6 @@
61 pass
62
63 def test_list_command_succeeds(self):
64- self.run_command('list')
65+ self.run_command('cli', 'list')
66 # The test is that we get here without error.
67 pass