Incorrect CLI usage should return non-zero exit code #52

Closed
dcarley opened this Issue May 14, 2014 · 2 comments

Comments

Projects
None yet
2 participants
@dcarley

dcarley commented May 14, 2014

If you supply an invalid command (not flag/option) and the usage message is printed to STDERR, aptly doesn't return a non-zero exit code to indicate a problem:

root@apt-1:~# aptly repo foo
aptly repo - manage local package repositories

Commands:

    add         add packages to local repository
    copy        copy packages between local repositories
    create      create local repository
    drop        delete local repository
    edit        edit properties of local repository
    import      import packages from mirror to local repository
    list        list local repositories
    move        move packages between local repositories
    remove      remove packages from local repository
    show        show details about local repository

Use "repo help <command>" for more information about a command.


Options:
  -architectures="": list of architectures to consider during (comma-separated), default to all available
  -config="": location of configuration file (default locations are /etc/aptly.conf, ~/.aptly.conf)
  -dep-follow-all-variants=false: when processing dependencies, follow a & b if depdency is 'a|b'
  -dep-follow-recommends=false: when processing dependencies, follow Recommends
  -dep-follow-source=false: when processing dependencies, follow from binary to Source packages
  -dep-follow-suggests=false: when processing dependencies, follow Suggests
root@apt-1:~# echo $?
0

The same is also true if you put your flags/options in the wrong place:

root@apt-1:~# aptly repo create foo -bar
Usage: aptly repo create <name>

aptly repo create - create local repository


Options:
  -architectures="": list of architectures to consider during (comma-separated), default to all available
  -comment="": any text that would be used to described local repository
  -component="main": default component when publishing
  -config="": location of configuration file (default locations are /etc/aptly.conf, ~/.aptly.conf)
  -dep-follow-all-variants=false: when processing dependencies, follow a & b if depdency is 'a|b'
  -dep-follow-recommends=false: when processing dependencies, follow Recommends
  -dep-follow-source=false: when processing dependencies, follow from binary to Source packages
  -dep-follow-suggests=false: when processing dependencies, follow Suggests
  -distribution="": default distribution when publishing
root@apt-1:~# echo $?
0

Whereas I'd expect an exit code of 2 so that the problem/misuse can be surfaced to other programs that might want to script aptly. Take grep for example:

root@apt-1:~# grep
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.
root@apt-1:~# echo $?
2

This doesn't appear to be trivial to fix because the usage functionality is deep within commander which only returns an error if the templating fails. Could be related to using another library in #50.

@dcarley dcarley referenced this issue in gds-operations/puppet-aptly May 15, 2014

Merged

Repository Create definition #3

@smira smira added this to the v0.6 milestone May 15, 2014

@smira smira added the bug label May 15, 2014

smira added a commit to smira/commander that referenced this issue May 15, 2014

@smira

This comment has been minimized.

Show comment
Hide comment
@smira

smira May 15, 2014

Member

Should be fixed in master, thanks!

Member

smira commented May 15, 2014

Should be fixed in master, thanks!

@smira smira closed this May 15, 2014

@dcarley

This comment has been minimized.

Show comment
Hide comment

dcarley commented May 15, 2014

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment