Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Issue 2301003: Massive overhaul for gcl help (Closed)

Created:
10 years, 7 months ago by M-A Ruel
Modified:
9 years, 7 months ago
Reviewers:
jam
CC:
chromium-reviews
Visibility:
Public.

Description

Massive overhaul for gcl help Automatically generate help and enforce stricter argument parsing. Stops from throwing an exception when run outside a subversion checkout. Fixed gcl lint. Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=48386

Patch Set 1 #

Unified diffs Side-by-side diffs Delta from patch set Stats (+178 lines, -205 lines) Patch
M gcl.py View 20 chunks +172 lines, -199 lines 0 comments Download
M tests/gcl_unittest.py View 3 chunks +6 lines, -6 lines 0 comments Download

Messages

Total messages: 3 (0 generated)
M-A Ruel
Here's some examples: > gcl help Usage: gcl <command> [options] Prints this help or help ...
10 years, 7 months ago (2010-05-27 01:41:44 UTC) #1
jam
lgtm, although I'm not familiar with some of the Python features you're using so this ...
10 years, 7 months ago (2010-05-27 02:35:42 UTC) #2
M-A Ruel
10 years, 6 months ago (2010-05-27 13:12:43 UTC) #3
On 2010/05/27 02:35:42, John Abd-El-Malek wrote:
> lgtm, although I'm not familiar with some of the Python features you're using
so
> this is mostly a rubber stamp

To recap;

dir(sys.module[__name__]) returns all the names (as string) of every 'named
objects' defined in this module, gcl.py. The named objects are the variable,
classes, functions and imports. So the code then filters out anything that
doesn't start with 'CMD' and the remaining ones are the supported subcommands.

For the decoration, there is 2 types. The ones without () and the active
function calls with ().

The ones that aren't a function call like @no_args is called once to return a
function object that will replace the function. I could have rewritten this as:

def tmpCMDopened():
  pass

CMDopened = no_args(tmpCMDopened)

So in fact it's the 'hook' function defined in no_args that is called, processes
'args' and then call the original function.

For attrs(), it's a bit different. The behavior is similar to:

def tmpCMDdiff(args):
  pass

CMDdiff = attrs(usage='<svn options>')(tmpCMDdiff)

In practice attrs doesn't install a hook but it _could_ have. It just modifies
the object.

For **kwargs, it's just a way to get all the arguments as a dictionary. i.e. for
attrs(usage='foo'), kwargs = { 'usage', 'foo' }

Powered by Google App Engine
This is Rietveld 408576698