jeffsilverm / nbmdt

network boot, monitor, and diagnostic tool
GNU General Public License v2.0
2 stars 0 forks source link

Parser issues: modes should be exclusive also configuration file is mandatory with --diagnose and --nominal #24

Closed jeffsilverm closed 5 years ago

jeffsilverm commented 5 years ago

The parser does not understand when the configuration file is given:

jeffs@jeffs-desktop:/home/jeffs/python/nbmdt  (i2mac+network) *  $ python3 nbmdt.py --diagnose xyzzy.json
...
usage: nbmdt.py [-h] [--boot] [--monitor] [--diagnose] [--test] [--nominal]
                [-p PORT] [--debug]
nbmdt.py: error: unrecognized arguments: xyzzy.json

Note that the help message (from the parser) is wrong. It should be something like:

usage: nbmdt.py [-h] --boot -p PORT|--monitor|--diagnose FILENAME|--test TEST_SPECIFICATION[,TEST_SPECIFICATION]|--nominal FILENAME   [--debug]

If the configuration filename is not given, then the error is detected:

jeffs@jeffs-desktop:/home/jeffs/python/nbmdt  (i2mac+network) *  $ python3 nbmdt.py --diagnose
...
Traceback (most recent call last):
  File "nbmdt.py", line 427, in <module>
    main()
  File "nbmdt.py", line 306, in main
    raise ValueError("You did not specify a configuration filename when you asked nbmdt to diagnose a system")
ValueError: You did not specify a configuration filename when you asked nbmdt to diagnose a system
jeffs@jeffs-desktop:/home/jeffs/python/nbmdt  (i2mac+network) *  $ 

While I am at it, add single letter options.

Also, look at the difference between action="store_true" and action="store_constant". So for example, instead of:

group.add_argument('--boot', '-b', help="Use at boot time.  Outputs messages color coded with status of network "
                                      "subsystems, and then exits", action="store_true", dest="boot")

Try:

group.add_argument('--boot', '-b', help="Use at boot time.  Outputs messages color coded with status of network "
                                      "subsystems, and then exits", action="store_const", dest="mode", const=constants.Modes.BOOT)

Then I can get rid of that tangles if... at the end of arg_parser.

jeffsilverm commented 5 years ago

I have modified nbmdt.py and test_nbmdt.py to deal with the problem, including how to test for it. See commits 24a119bc3e76c0c6e085c09ab4bfa4054b7b4bd1 and 8a195a9cd76c53a10d9209b8b9712ea644b21af3