csaf-poc / csaf_distribution

Tools to download or provide CSAF (Common Security Advisory Framework) documents.
https://csaf.io
38 stars 22 forks source link

Give usage information on bad invocation #68

Closed bernhardreiter closed 2 years ago

bernhardreiter commented 2 years ago

Would be nice to give usage information if options or parameters fail or if -h or --help is given explitly at all. Currently:

./csaf_checker -t html example.com -h
unknown flag `t'
2022/02/25 17:46:33 error: unknown flag `t'

So I need to call it all just with -h without extra parameters. If -h is present it should be executed and then execution should stop.

JanHoefelmeyer commented 2 years ago

Reproduced problem: "version": "0.9.2-10-g006f088" "date": "2022-06-20T11:25:55.905500312Z"

~/csaf_distribution# ./bin-linux-amd64/csaf_checker -t html example.com -h unknown flag t' 2022/06/20 13:26:00 error: unknown flagt'

Plan:

Step 1: Look for -h or --help in parameters, and if they exist, print help and stop execution. Step 2: If neither was found, if a command line error occurred, print help and error message.

bernhardreiter commented 2 years ago

It seems that there are a number of GNU/Linux tools, which do behave the same way, e.g.

LANG=C awk -f gib -h
awk: fatal: can't open source file `gib' for reading (No such file or directory)
 env LANG=C awk -h -f gib
Usage: awk [POSIX or GNU style options] -f progfile [--] file ...
Usage: awk [POSIX or GNU style options] [--] 'program' file ...
POSIX options:          GNU long options: (standard)
        -f progfile             --file=progfile
[..]

(this is at least an example, there are others and example for different behaviour)

Trying to solve it, it seems that https://github.com/jessevdk/go-flags does not have a documented way of getting to know if the --help flag was given. So we would need to work around it, which may not be worth the effort. So closing as won't improve.