torognes / swarm

A robust and fast clustering method for amplicon-based studies
GNU Affero General Public License v3.0
123 stars 23 forks source link

How to handle duplicated parameters or options? #101

Closed frederic-mahe closed 7 years ago

frederic-mahe commented 7 years ago

hello, what should swarm do if an option is passed twice?

printf ">a_2\nAAAA\n>b_1\nAAAT\n" | swarm -o file1 -o file2 2> /dev/null

as of now, swarm does not complain and writes in file2. I am perfectly OK with that, but other tools behave differently:

# ls doesn't care
ls -a -a
# sort stops with an error message
printf "1\n2\n3\n" | sort -nr -o tmp1 -o tmp2
sort: multiple output files specified

I don't know what is the best way to behave. Should swarm issue a warning and keep running? Either way, that behavior should be documented in the man page, something like "if the same option is passed twice, only the value of the last option is retained".

What do you think?

colinbrislawn commented 7 years ago

I guess I kind of like the idea of throwing an error and stopping. I feel like duplicate flags might be a mistake made by new users, and throwing an error would force them to find it and fix it. They might miss this if the script completes silently or if it's only in the man page, which new users rarely read.

In a more general sense, should duplicated parameters be accepted for other options? swarm -i example.fna -d 1 -d 2 > output.txt Are non-existent parameters accepted? swarm -i example.fna --biomout example.biom

If you only accept valid and unambiguous flags, the opportunity of confusion is reduced.

torognes commented 7 years ago

Ideally it should complain if the same option is passed more than once. It will complain now if non-existing options are specified.

This behaviour could be implemented with a bool array (bitmap) indicating which options are specified, and by checking if each option has already been encountered.

torognes commented 7 years ago

See also issue #77

torognes commented 7 years ago

Duplicated options now trigger a fatal error with this message: Error: Option -x or --xxxxxx specified more than once.

frederic-mahe commented 7 years ago

Perfect. Passing non-existing or duplicated options is already covered by unit tests, so I think we can close that issue.