`snap --help install ...` unexpectedly performs the install

I’ve been running in to some problems running an install command:

snap install --edge --classic <snap>

and I wanted to try and get some extra output from snap in order to help me debug. I appended --help to my command to find out if there were any options like --debug or --verbose:

snap install --edge --classic <snap> --help

but this only showed me the help for snap install, which didn’t help me. Figuring that there might be some global options to the snap command, I tried moving --help to be right after snap:

snap --help install --edge --classic <snap>

--help was unexpectedly ignored entirely, and the install command ran! This, to me, is unexpected behaviour. Fortunately for me, the command running unexpectedly in this case wasn’t a problem; if I had been trying to get help on how to do something more destructive then this could have been Very Bad.

3 Likes

(The snap installed after waiting a couple of minutes, so it was an ephemeral issue that didn’t require any further debugging.)

gosh, nice bug, well spotted. I’ll fix it.

3 Likes

FWIW, global options would be listed in the command’s help, below the per-command options (we don’t currently have any, but I’ve toyed with the idea of making --unicode and --color global)

fix is up

edit: now on master

1 Like

Thanks for the speedy response!

Just FYI:

snap help help

Will show how to use help! Note that there is NO ‘–’ before help, just plain ‘help’.

If I understand the fix correctly, this makes snap --help install equivalent to snap help, not snap help install. In all sensible option parsing (oh, boy do I hate go’s command line parsing) --help foo and foo --help are equivalent.

that is correct, given that help is a command, so snap help help runs the help command asking about the help command.

#snappy irc logs from 2019-06-07 @
Chipaca what I’d rather have happen is that snap --help foo and snap foo --help mean the same thing 09:09
Chipaca but, sadly, go-flags does not let me do that 09:09
Chipaca so you get the global help ¯\(ツ) 09:09
jamesh Chipaca: maybe what the world needs is another command line parsing library? 09:36
Chipaca jamesh: I’ve got one on my list to look into 09:37
Chipaca jamesh: but it is very tempting 09:37
Chipaca jamesh: kingpin i’m told is alright 09:38
2 Likes

We are using cobra and it supports your needs. I have no experience with other libraries though and cannot compare them.

1 Like