Closed Bug 1318268 Opened 9 years ago Closed 9 years ago

CLI is broken with ArgParse implementation

Categories

(Localization Infrastructure and Tools :: compare-locales, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: flod, Assigned: Pike)

References

Details

Attachments

(1 file, 2 obsolete files)

I'm not sure if it's just something wrong in my setup, but compare-locales from command line is completely broken if installed from the current tip. This is probably beyond my ability to fix, so feel free to take over and redo it properly. That's also why I'm not using mozreview for it. If I run compare-locales without arguments, I get this error Traceback (most recent call last): File "/usr/local/bin/compare-locales", line 9, in <module> load_entry_point('compare-locales==1.2', 'console_scripts', 'compare-locales')() File "build/bdist.macosx-10.11-intel/egg/compare_locales/commands.py", line 58, in call import os File "build/bdist.macosx-10.11-intel/egg/compare_locales/commands.py", line 67, in handle_ # Make command argument from directory and pathname (prefix space, add quotes). NameError: global name 'options' is not defined Which seems related to remnant of the optparse syntax http://stackoverflow.com/questions/19076842/the-pythons-argparse-errors In other places there are other issues, like using args as an array (slice, len).
Attached patch bug1318268.patch (obsolete) — — Splinter Review
Attachment #8811637 - Flags: feedback?(l10n)
Attached patch bug1318268v1.patch (obsolete) — — Splinter Review
Even better without a random line in it.
Attachment #8811637 - Attachment is obsolete: true
Attachment #8811637 - Flags: feedback?(l10n)
Attachment #8811638 - Flags: feedback?(l10n)
Comment on attachment 8811638 [details] [diff] [review] bug1318268v1.patch Review of attachment 8811638 [details] [diff] [review]: ----------------------------------------------------------------- ::: compare_locales/commands.py @@ -130,5 @@ > return parser > > - def handle(self, args, options): > - if len(args) != 2: > - self.parser.error('Reference and localizatino required') Since it's easy to miss, there's a typo fixed here.
Comment on attachment 8811638 [details] [diff] [review] bug1318268v1.patch I've taking this patch as inspiration, but I don't think that there are a lot of codes left of your patch, so I'm flinging things around. Taking this bug, review request on you ;-) And sorry for not testing the original landing even remotely :-(
Attachment #8811638 - Flags: feedback?(l10n) → feedback-
Assignee: nobody → l10n
Status: NEW → ASSIGNED
Attachment #8811638 - Attachment is obsolete: true
Comment on attachment 8811851 [details] Bug 1318268 - Fix options parsing from command line, https://reviewboard.mozilla.org/r/93774/#review94132 It looks good, just a nit on a variable name ::: compare_locales/commands.py:89 (Diff revision 1) > > def get_parser(self): > parser = super(CompareLocales, self).get_parser() > + parser.add_argument('ini_file') > + parser.add_argument('l10n_base_dir') > + parser.add_argument('locale', nargs='*') nit: maybe this should be "locales"? ::: compare_locales/commands.py:143 (Diff revision 1) > If none are given, test all locales in manifest.webapp or files.""" > > def get_parser(self): > parser = super(CompareWebApp, self).get_parser() > + parser.add_argument('webapp') > + parser.add_argument('locale', nargs='*') Same here: locales?
Attachment #8811851 - Flags: review?(francesco.lodolo) → review+
That's a deficiency in argparse, as I'm now letting it define usage, and only deliver description. With 'locale' being the argument name, this generates usage: compare-locales [-h] [--version] [-v] [-q] [-m MERGE] [--clobber-merge] [-r REFERENCE] [--data {text,exhibit,json}] ini_file l10n_base_dir [locale [locale ...]] which looks better than using 'locales'. I tried using dest='locales', but that's not working good for positional arguments :-/. Thanks for the r+
I think you can use metavar for that? https://docs.python.org/2/library/argparse.html#metavar parser.add_argument('locales', metavar="locale", nargs='*') $ compare-locales usage: compare-locales [-h] [--version] [-v] [-q] [-m MERGE] [--clobber-merge] [-r REFERENCE] [--data {text,exhibit,json}] ini_file l10n_base_dir [locale [locale ...]] compare-locales: error: too few arguments
Nice, yes.
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: