MantisBT - Doomseeker
View Issue Details
0003249Doomseeker[All Projects] Suggestionpublic2017-09-01 18:062018-10-27 22:55
WubTheCaptain 
Pol M 
normaltweakalways
closedfixed 
x86_64Debian GNU/Linuxbuster/sid
1.1 
1.21.2 
0003249: Change Doomseeker to fail on invalid command line option
Say I made a typo and instead of "--datadir /foo/bar/" option I omitted a character and had a typo "--datdir /foo/bar", Doomseeker would still start but with wrong (default) IP2C or plugin data I didn't intend to use. There's also a possibility of not understanding what went wrong in the case.
$ doomseeker --foo-bar --this-is-not-a-real-option
[20:48:56] Starting Doomseeker. Hello World! :)
...


(Doomseeker starts normally.)
Behavior with unrecognized options varies between programs. Few examples are listed below.

$ cat --foo-bar --this-is-not-a-real-option
cat: unrecognized option '--foo-bar'
Try 'cat --help' for more information.


$ slock --foo-bar --this-is-not-a-real-option                               
usage: slock [-v] [cmd [arg ...]]


$ gcc --foo-bar --this-is-not-a-real-option
gcc: error: unrecognized command line option ‘--foo-bar’
gcc: error: unrecognized command line option ‘--this-is-not-a-real-option’
gcc: fatal error: no input files
compilation terminated.


$ mpv --foo-bar --this-is-not-a-real-option
Error parsing option foo-bar (option not found)
Setting commandline option --foo-bar= failed.

Exiting... (Fatal error)


§ firefox --foo-bar --this-is-not-a-real-option
[Firefox starts normally.]


To improve user experience, I would suggest Doomseeker to fail with an informative message when a command line option for Doomseeker which doesn't exist is attempted.


  • http://man7.org/linux/man-pages/man3/getopt.3.html

  • http://pubs.opengroup.org/onlinepubs/9699919799/functions/getopt.html from POSIX.1-2008 (2016)

No tags attached.
Issue History
2017-09-01 18:06WubTheCaptainNew Issue
2017-10-25 00:48WubTheCaptainCategoryBug => Suggestion
2017-10-25 00:48WubTheCaptainSummaryDoomseeker doesn't fail on invalid command line option => Change Doomseeker to fail on invalid command line option
2017-10-25 00:48WubTheCaptainNote Added: 0018624
2017-10-25 00:56WubTheCaptainAdditional Information Updatedbug_revision_view_page.php?rev_id=11194#r11194
2017-10-25 01:00WubTheCaptainNote Added: 0018625
2017-10-25 01:00WubTheCaptainNote Edited: 0018625bug_revision_view_page.php?bugnote_id=18625#r11196
2018-08-05 23:01Pol MNote Added: 0019312
2018-08-05 23:15Pol MNote Edited: 0019312bug_revision_view_page.php?bugnote_id=19312#r11602
2018-08-05 23:27Pol MNote Edited: 0019312bug_revision_view_page.php?bugnote_id=19312#r11603
2018-08-06 09:13Pol MNote Edited: 0019312bug_revision_view_page.php?bugnote_id=19312#r11604
2018-08-12 11:45ZalewaNote Added: 0019324
2018-08-12 11:45ZalewaAssigned To => Zalewa
2018-08-12 11:45ZalewaStatusnew => needs testing
2018-08-20 18:13WubTheCaptainNote Added: 0019340
2018-08-20 18:13WubTheCaptainStatusneeds testing => needs review
2018-08-20 19:00WubTheCaptainTarget Version => 1.2
2018-08-20 19:22Pol MNote Added: 0019346
2018-08-21 13:16Pol MNote Edited: 0019346bug_revision_view_page.php?bugnote_id=19346#r11654
2018-08-21 23:47ZalewaAssigned ToZalewa => Pol M
2018-08-21 23:47ZalewaStatusneeds review => assigned
2018-09-21 20:55Pol MNote Added: 0019601
2018-09-21 20:55Pol MStatusassigned => needs review
2018-09-22 01:09WubTheCaptainNote Added: 0019604
2018-09-22 01:12WubTheCaptainNote Added: 0019605
2018-09-22 01:12WubTheCaptainNote Edited: 0019605bug_revision_view_page.php?bugnote_id=19605#r11883
2018-09-22 01:13WubTheCaptainNote Edited: 0019605bug_revision_view_page.php?bugnote_id=19605#r11884
2018-09-22 01:16WubTheCaptainNote Added: 0019606
2018-09-22 06:41ZalewaNote Added: 0019621
2018-09-22 08:46Pol MNote Added: 0019622
2018-09-22 08:59Pol MNote Added: 0019623
2018-09-22 09:00Pol MNote Added: 0019624
2018-09-22 09:32ZalewaNote Added: 0019625
2018-09-22 09:46Pol MNote Added: 0019626
2018-09-22 09:48Pol MNote Edited: 0019626bug_revision_view_page.php?bugnote_id=19626#r11898
2018-09-22 09:53ZalewaNote Added: 0019627
2018-09-22 09:53ZalewaNote Edited: 0019627bug_revision_view_page.php?bugnote_id=19627#r11900
2018-09-22 09:54Pol MNote Added: 0019628
2018-09-22 13:23WubTheCaptainNote Added: 0019631
2018-09-22 13:23WubTheCaptainStatusneeds review => resolved
2018-09-22 13:23WubTheCaptainFixed in Version => 1.2
2018-09-22 13:23WubTheCaptainResolutionopen => fixed
2018-10-27 22:55WubTheCaptainStatusresolved => closed

Notes
(0018624)
WubTheCaptain   
2017-10-25 00:48   
Changed from a bug into a suggestion.
(0018625)
WubTheCaptain   
2017-10-25 01:00   
Nevermind me linking additional information to getopt, getopt_long() are GNU extensions but I think the part about "?" (an error) is worth looking more into.

(0019312)
Pol M   
2018-08-05 23:01   
(edited on: 2018-08-06 09:13)
since --rcon is a two-argument option, getopt and getopt_long maybe are not the best way to handle the argv of doomseeker. those cannot handle two-argument options, and the ideas I've found to explicitly use getopt_long seem to require modifications to the way the command is handled, for instance:
doomseeker --rconplugin [plugin] --rconip [ip]
doomseeker --rcon [plugin]=[ip]
doomseeker --rcon "[plugin] [ip]"
I can do what you ask, even without getopt. but if we want to use getopt_long, it looks like it could change the way argv works for the end user. In case that getopt_long can handle multiple arguments and I'm simply horrible at googling, please tell me :)

Also, I think that doomseeker should also stop if an option with an obligatory argument is ran without it. It should also fail.

EDIT: For instance, I've made a fork that would do exactly what you're asking for. (hg clone'https://Pol_M@bitbucket.org/Pol_M/doomseeker-addr-0003249 [^]')

(0019324)
Zalewa   
2018-08-12 11:45   
'https://bitbucket.org/Doomseeker/doomseeker/commits/fb5c8efef13ccf43e6daec260711e20b04d32f3a [^]'
(0019340)
WubTheCaptain   
2018-08-20 18:13   
I don't like this if-else soup and code duplication that is being brewed from code quality perspective, but the patch functionality seems to be working fine as of hg changeset 2205:aafacb71daee.

Would you clean up the code? Else, close this bug as resolved.
(0019346)
Pol M   
2018-08-20 19:22   
(edited on: 2018-08-21 13:16)
Ok, I'll try to keep it a little bit more tidy with a switch, and I think I can cut a few other lines.
EDIT: Forgot that C++ switch did not work with Strings. Still, I'll try to cut repeated code.

(0019601)
Pol M   
2018-09-21 20:55   
pull request
(0019604)
WubTheCaptain   
2018-09-22 01:09   
I still wish we didn't have this if-else string comparison code, it's nasty; But fair enough. At least the duplicate tr() is gone.

Zalewa requested to fix typos... not sure what that means. "doomseeker" being lowercase?
(0019605)
WubTheCaptain   
2018-09-22 01:12   
(edited on: 2018-09-22 01:13)
Quote from WubTheCaptain
Zalewa requested to fix typos... not sure what that means. "doomseeker" being lowercase?


Ah, you had already fixed those typos with commit 26b892cf41c197aa2b6d4c59af2b657ef804048a.

I'm not sure if "doomseeker" should be all lowercase or first letter capitalized. (Or there at all.)

(0019606)
WubTheCaptain   
2018-09-22 01:16   
Quote from Pol M
pull request


Side-note again about pull requests: It'd be easier to find the relevant pull requests if the PR title (currently "Addresses ticket 0003249 from WubTheCaptain") would be at the end of description, and the title descriptively said something like "Cleanup Main::interpretCommandLineParameters()" or similar.
(0019621)
Zalewa   
2018-09-22 06:41   
Quote from "WubTheCaptain"

fix typos... "doomseeker" being lowercase?

Nah, that's fine.
(0019622)
Pol M   
2018-09-22 08:46   
Quote from WubTheCaptain
Side-note again about pull requests: It'd be easier to find the relevant pull requests if the PR title (currently "Addresses ticket 0003249 from WubTheCaptain") would be at the end of description, and the title descriptively said something like "Cleanup Main::interpretCommandLineParameters()" or similar.

Ok, I'll put a more descriptive title and leave the number of the ticket for the end of the description.

Also, I'd like to add that it seems that bitbucket does not have bookmarks especially well integrated. When I sync with the official repo, It also tries to merge heads, completely ignoring the bookmarks. To solve this, either I strip the merge commit that bitbucket generates (fortunately I'm the only one using my repo, so manipulating history before I pull changes shouldn't be bad.) or I use branches, which are well integrated. For the moment I'll proceed with the first option, but if someone has a better idea, let me know :)
(0019623)
Pol M   
2018-09-22 08:59   
Quote from WubTheCaptain
I still wish we didn't have this if-else string comparison code, it's nasty; But fair enough.

I don't like having an if/else chain there, I'd use a switch. But since C++'s switch does not support strings, it would be a little bit difficult. An option would be to transform the strings to numbers through some conversion, or an enum and a map trick. Both options don't really convince me for this purpose.
(0019624)
Pol M   
2018-09-22 09:00   
If WubTheCaptain is okay with the changes, I'll "resolve" this ticket.
(0019625)
Zalewa   
2018-09-22 09:32   
I was able to successfully use bookmarks to contribute to Zandronum, albeit it was a while ago and I don't quite remember the details of operations. IIRC I operated partially in TortoiseHg UI and partially from the command prompt as CMD was too clumsy for some purposes and the GUI did not have all the options.

Quote from "Pol M"
I don't like having an if/else chain there, I'd use a switch. But since C++'s switch does not support strings, it would be a little bit difficult. An option would be to transform the strings to numbers through some conversion, or an enum and a map trick. Both options don't really convince me for this purpose.


I suppose this could be done by using a std::map<string, ArgHandler*> object with ArgHandler having polymorphed implementations to handle each argument, or even avoid using std::map and have an array of ArgHandler with '.arg()' method returning the string to compare to but with the version of C++ we use the code would actually be even worse.

C++11 (or is it 14?) has lambdas, which would improve this ordeal a bit, though I'm also unconvinced that the result would be any better.

Maybe Wub knows of some example that we could look at? A one that preferably doesn't use an external library.
(0019626)
Pol M   
2018-09-22 09:46   
(edited on: 2018-09-22 09:48)
Quote from Zalewa
I was able to successfully use bookmarks to contribute to Zandronum, albeit it was a while ago and I don't quite remember the details of operations. IIRC I operated partially in TortoiseHg UI and partially from the command prompt as CMD was too clumsy for some purposes and the GUI did not have all the options.


The error I mention occurs only when I sync my repo with the official repo. I'm unaware if it is a mistake of the way I use bookmarks, but I'll confidently say that this time it is not my fault. :)

Quote from Zalewa
I suppose this could be done by using a std::map<string, ArgHandler*> object with ArgHandler having polymorphed implementations to handle each argument, or even avoid using std::map and have an array of ArgHandler with '.arg()' method returning the string to compare to but with the version of C++ we use the code would actually be even worse.

C++11 (or is it 14?) has lambdas, which would improve this ordeal a bit, though I'm also unconvinced that the result would be any better.


That's what I've thought. :/ (C++11)

(0019627)
Zalewa   
2018-09-22 09:53   
Quote from "Pol M"
The error I mention occurs only when I sync my repo with the official repo. I'm unaware if it is a mistake of the way I use bookmarks, but I'll confidently say that this time it is not my fault. :)


Ah, I see now. I never used the "Sync" button on Bitbucket's webpage. I pulled everything from the official repo to a repository on my local machine and then pushed it back to my repo on the site. It gives you a lot more flexibility in deciding what goes where.

(0019628)
Pol M   
2018-09-22 09:54   
Oh, I'll test this 🤔
(0019631)
WubTheCaptain   
2018-09-22 13:23   
Quote from Zalewa
Maybe Wub knows of some example that we could look at? A one that preferably doesn't use an external library.


I won't be spending any more time on resolving the if-else soup. C++ is not my cup of tea. Besides, it's not entirely in scope of this ticket to resolve; Create a child ticket if needed.

Since this has been merged with merge commit 365d5abf3b5a3c10c1dd01114b6d21572c6cb5aa, I assume this ticket is resolved.