cve-search / cpe-guesser

Tool to guess CPE name based on common software name
https://cve-search.github.io/cpe-guesser/
BSD 2-Clause "Simplified" License
81 stars 14 forks source link

chg: [lookup] use positional arguments for WORD(s) #6

Closed oh2fih closed 3 years ago

oh2fih commented 3 years ago

I could have posted this as an issue, but with a pr it's easier to demonstrate this alternative. I'm actually asking to clarify whether there are plans to add any other lookup types than the --word WORD? That would make the current syntax a well-founded decision.

Otherwise, for the ease of use, would it be ok to alter the syntax from

usage: lookup.py [-h] [--word WORD]

python3 lookup.py  --word microsoft --word sql --word server | jq .

to positional arguments:

python3 lookup.py microsoft sql server | jq .
usage: lookup.py [-h] WORD [WORD ...]

Find potential CPE names from a list of keyword(s) and return a JSON of the results

positional arguments:
  WORD        One or more keyword(s) to lookup

optional arguments:
  -h, --help  show this help message and exit

Actually, the current help is a bit contradictory, as the --word argument seems both mandatory and optional at the same time:

Missing keyword(s)
usage: lookup.py [-h] [--word WORD]

Find potential CPE names from a list of keyword(s) and return a JSON of the results

optional arguments:
  -h, --help   show this help message and exit
  --word WORD  One or more keyword(s) to lookup

With nargs='+' the argparse module internally handles the exception of not giving any arguments, printing the usage:

usage: lookup.py [-h] WORD [WORD ...]
lookup.py: error: the following arguments are required: WORD

You can merge if you agree, but I wouldn't mind if there were other plans and you'd choose to close this pr. (The documentation is updated accordingly on the same commit.)

adulau commented 3 years ago

I'll merge it. The original idea (which is still an idea) was to have some additional keywords such as "out-of-vocabulary" name. But this would work with positional arguments as we could an additional option with the type of word we are searching for.