Skip to content

CLI Look and Feel - Option Groups#744

Merged
qwcode merged 23 commits intopypa:developfrom
gvalkov:cli-optgroups
Dec 14, 2012
Merged

CLI Look and Feel - Option Groups#744
qwcode merged 23 commits intopypa:developfrom
gvalkov:cli-optgroups

Conversation

@gvalkov
Copy link
Contributor

@gvalkov gvalkov commented Dec 10, 2012

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)

@gvalkov gvalkov mentioned this pull request Dec 10, 2012
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll admit that this is lame ...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather see the code import the names it needs from optparse, or just use optparse.make_option.

@qwcode
Copy link
Contributor

qwcode commented Dec 11, 2012

pip <command> -h seems to be broken

$ pip install -h
Usage: pip install [OPTIONS] PACKAGE_NAMES...

no such option: -h

Makefile Outdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this Makefile really get merged into develop branch?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make any difference if I turned it into a fabfile instead? It's just for convenience after all.

@hltbra
Copy link
Contributor

hltbra commented Dec 12, 2012

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.

@qwcode
Copy link
Contributor

qwcode commented Dec 12, 2012

@gvalkov lgtm, but one more thought. maybe the general options should be last, and not first.
gem does it that way. what was your thinking on that?

@qwcode
Copy link
Contributor

qwcode commented Dec 12, 2012

@hltbra, @pfmoore, @pnasrat, hey, are you guys thumbs up on these option groups? I am.
the only remaining issue from me would be whether the general options should be first or last. I'm thinking last?

@pfmoore
Copy link
Member

pfmoore commented Dec 12, 2012

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.
@gvalkov
Copy link
Contributor Author

gvalkov commented Dec 12, 2012

@hltbra, I've commented on #415. Wouldn't a Makefile/Fabfile/Rakefile be a useful thing to have for such things? Sticking the man page generation in setup.py wouldn't be a problem, but a Makefile would be a more general solution.

@pfmoore
Copy link
Member

pfmoore commented Dec 12, 2012

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?

@gvalkov
Copy link
Contributor Author

gvalkov commented Dec 12, 2012

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.

@hltbra
Copy link
Contributor

hltbra commented Dec 12, 2012

LTGM also, @qwcode, @pfmoore, @gvalkov. This pull request is a great enhancement to pip.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you just want just move on at this point, I'm ok with merging this, and I'll make some tweeks afterwards.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. 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.
  2. Longer term, probably in a subsequent commit, refactor the code to make insert_option_group the primitive, and implement add_option_group in 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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@qwcode
Copy link
Contributor

qwcode commented Dec 14, 2012

@gvalkov completion seems to be broken since your last pull:

 File "/home/qwcode/p/pypa/pip2/pip/__init__.py", line 63, in autocomplete
  for opt in subcommand.parser.option_list
AttributeError: type object 'SearchCommand' has no attribute 'parser'

subcommand here is a class, when this is expecting an instance
lets fix this in this pull.

so that's 2 problems I've found (this one, and the pip <command> -h failure), but the tests ran clean, right?

so, we need tests that cover these 2 problems, so we can't break this again, and not notice it.

@gvalkov
Copy link
Contributor Author

gvalkov commented Dec 14, 2012

@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 pip --log <arg> install --user <arg> works then maybe we don't have to. This information can be conveyed in the command's usage string, e.g:

pip [options] install [options] <package> [<package> ...]

Anyway, just an idea.

@qwcode
Copy link
Contributor

qwcode commented Dec 14, 2012

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That wasn't intentional. I think I just forgot to remove one of the lines. Incoming fix!

qwcode added a commit that referenced this pull request Dec 14, 2012
CLI Look and Feel - Option Groups
@qwcode qwcode merged commit f689f10 into pypa:develop Dec 14, 2012
@qwcode
Copy link
Contributor

qwcode commented Dec 14, 2012

Merged. @gvalkov , thanks for being so quick in your responses. I'll update the release notes as well.

@gvalkov gvalkov mentioned this pull request Dec 16, 2012
@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Jun 5, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

auto-locked Outdated issues that have been locked by automation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants