CLI Look and Feel - Option Groups#744
Conversation
Note that commands still have to add the option group to the parser once they populate it with options (self.parser.add_option_group).
The show-help-output target makes it easy to see the help output of all non-hidden pip commands.
pip/commands/freeze.py
Outdated
There was a problem hiding this comment.
I'll admit that this is lame ...
There was a problem hiding this comment.
what's lame about it?
in the previous pull you weren't using "Command Options", but rather "Install Options", etc..
why the change? I think I prefer "Install Options", "Freeze Options", etc...
There was a problem hiding this comment.
The fact that you have to do it by hand in every command. I think I'll keep self.cmd_opts, but change self.cmd_opts.title in every command. Or initialize the optgroup as OptionGroup(parser, '%s Options' % name.capitalize()). I don't feel like importing optparse in every command module.
pip/baseparser.py
Outdated
There was a problem hiding this comment.
I'd rather see the code import the names it needs from optparse, or just use optparse.make_option.
|
|
Makefile
Outdated
There was a problem hiding this comment.
Should this Makefile really get merged into develop branch?
There was a problem hiding this comment.
Would it make any difference if I turned it into a fabfile instead? It's just for convenience after all.
|
I questioned you about the Makefile, and it reminds me this man page request issue (#415). It would be great if someone work that out. |
|
@gvalkov lgtm, but one more thought. maybe the general options should be last, and not first. |
|
Looks good to me. General options at the end seems right to me (if it were only -h and -v I'd be OK with at the start, but there are enough general options that the end seems cleaner (look for example at pip freeze where there are more general options than command-specific ones). |
Add a new base parser class 'CustomOptionParser' that provides the 'insert_option_group(idx, *, **)' method for inserting an option group at a specific position.
|
The makefile won't work on Windows. If you're not expecting it to be cross-platform, why not just make it a shell script so it doesn't look like anything other than a convenience for Unix users? |
|
What else can you mistake it for? Like you said, this is just a non-portable convenience for Unix users. I see nothing wrong with that (well, except the beautiful way in which Makefiles and multi-line bash mix together). Anyway, I don't feel like debating this any further, so I'll just remove it. |
There was a problem hiding this comment.
I just saw this showed up in the last commit. I'm not fond of this add/pop/insert routine.
why not just use this in the command classes? self.parser.option_groups.insert(0, grpname)
if you did want to add a helper, why not just add it into the existing ConfigOptionParser class, and why is the logic add/pop/insert, instead of just insert?
There was a problem hiding this comment.
if you just want just move on at this point, I'm ok with merging this, and I'll make some tweeks afterwards.
There was a problem hiding this comment.
I'm guessing you did the add/pop/insert routine so it would originally be added using the "public" interface, add_option_group . that makes sense, but you still end up breaking the public interface by doing the pop/insert afterwards. to be pure I think, we'd restructure things so we added them in order only using 'add_option_group'.
There was a problem hiding this comment.
There isn't much point in reimplementing most of add_option_group when the only 'stateful' thing it does is append to option_groups. I'm also fine with self.parser.option_group.insert(idx, group), but I really think my solution is good enough, so I'll let you sort it out anyway you find appropriate post-merge.
There was a problem hiding this comment.
@pfmoore hey, curious what your response to this thread about option groups is, specifically, whether we should worry about only using "add_option_group" (and not inserting directly into parser.option_groups). I can see in the current optparse code that it doesn't matter, but still concerns me.
There was a problem hiding this comment.
I've been watching the comments, but to be honest I don't think it's a huge deal. The code is annoyingly obscure, but I can see the point about not duplicating the whole of add_option_group. It seems to me that one of two things should be done:
- Add a comment before the pop/insert, clarifying why it's done this way. This is a short-term solution, but good enough for now.
- Longer term, probably in a subsequent commit, refactor the code to make
insert_option_groupthe primitive, and implementadd_option_groupin terms of it (that'd be a one-liner using a hard-coded idx value, presumably).
If @gvalkov feels like doing the refactoring now, that's great, but I wouldn't hold up the commit for it.
There was a problem hiding this comment.
I tinkered with this last night, and what I ended up doing is having the subcommands add/insert groups to a simple list property of the command, and then when command.main() runs, it uses optparse.add_option_group to add to the parser from the list in order. no direct index inserts. but this could happen later outside the scope of this pull.
|
@gvalkov completion seems to be broken since your last pull: subcommand here is a class, when this is expecting an instance so that's 2 problems I've found (this one, and the so, we need tests that cover these 2 problems, so we can't break this again, and not notice it. |
|
@qwcode, completion has been fixed in the latest round of commits. I was wondering if we could do without showing 'General Options' for every command. If
Anyway, just an idea. |
|
I'm getting ready to do a final check on this and merge. as for your next round of user-facing help changes, I think it's better to hit the mailing list with various plans, and come to a consensus there, and then the pull is just about implementation details, not a mixture of both. |
pip/__init__.py
Outdated
There was a problem hiding this comment.
this didn't just fix completion, it changed it's behavior.
e.g for "pip install --" completion, it used to give install options and general options (excluding those marked as SUPPRESS_HELP)
now it shows everything,
"pip --" completion is still the same in that it still excludes the suppressed ones.
how about let's just fix completion and not change it.
if you want to change it, lets include that in your plans for your next pull.
There was a problem hiding this comment.
That wasn't intentional. I think I just forgot to remove one of the lines. Incoming fix!
CLI Look and Feel - Option Groups
|
Merged. @gvalkov , thanks for being so quick in your responses. I'll update the release notes as well. |
This pull requests splits all command options into 'General' and 'Command' options. Output of all help commands can be seen here (generated with
make show-help-output)