Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Submit feedback
    • Contribute to GitLab
  • Sign in
UW-Glance
UW-Glance
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 27
    • Issues 27
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 1
    • Merge Requests 1
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI / CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Eva Schiffer
  • UW-GlanceUW-Glance
  • Issues
  • #28

Closed
Open
Opened Dec 17, 2018 by Alan De Smet@adesmet
  • Report abuse
  • New issue
Report abuse New issue

Make the command a first tier argument

The command ("info", "reportGen", etc) should be a first tier argument, not just squirreled away as the first entry in arguments (or options.misc after #26).

I think it should be as straightforward as adding

    parser.add_argument('command', metavar="COMMAND", help="command to invoke", nargs=1, type=str.lower)

(The type=str.lower makes it case insensitive.)

This will cause glance to automatically fail with an error if no command is provided. The error will look something like:

usage: [-h] COMMAND
glance: error: too few arguments

I think that's a feature.

We'd need to modify

    parser.add_argument('misc', metavar='COMMAND [FILE [VARIABLE]]+', nargs='*')

to remove the COMMAND bit.

The logic in main in compare.py should change from

    # if what the user asked for is not one of our existing functions, print the help
    if ((not args) or (args[0].lower() not in lower_locals)):
        if options.version:
            return 0
        options.print_help()
        help()
        return 9
    else:
        # call the function the user named, given the arguments from the command line, lowercase the request to ignore case
        rc = lower_locals[args[0].lower()](*args[1:])
        return 0 if rc is None else rc

to

    # if what the user asked for is not one of our existing functions, print the help
    if ((options.command is None or options.command == "") or (options.command.lower() not in lower_locals)):
        if options.version:
            return 0
        options.print_help()
        help()
        return 9
    else:
        # call the function the user named, given the arguments from the command line, lowercase the request to ignore case
        rc = lower_locals[options.command.lower()](*args)
        return 0 if rc is None else rc

For bonus points, have main() pass a list of valid commands in to parse_arguments(), and use that to set a list of choices= so argparse can automatically filter invalid commands.

Edited Dec 17, 2018 by Alan De Smet
To upload designs, you'll need to enable LFS. More information
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
1
Labels
argparse
Assign labels
  • View project labels
Reference: evas/UW-Glance#28