Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Validate commandline arg values, and unify -help documentation #225
This resolves #172
Re-works the AllowedArgs class to be instantiable and add methods for building and verifying the set of allowed arguments, values, and associated help message. Creates a child class of AllowedArgs for each executable, and for the config file.
In addition, this change moves several constants from .cpp files into .h files, so they are accessible from the AllowedArgs class. It also adds test cases for invalid argument names and values.
Command-line values are verified by grouping all existing arguments into one of six possible value types:
Some arguments could have more strict checks (e.g.,
Note that I considered using regular expressions to validate the argument values, however the std::regex library isn't supported in gcc versions prior to 4.9. Also, the windows executables did not work when using regular expressions. So, although creating custom helper functions for each type is more verbose than simply using a regex, this approach is more portable.
All help message documentation (the text that is output up if you run an executable with the
The design of the AllowedArgs class is inspired by the
On a pure line-count, this change is relatively large. However, the majority of the lines changed are simply moving the help documentation from wherever it was located in the codebase into the AllowedArgs class. In order to ease reviewing, this pull request consists of two git commits (each of which are compilable and have all tests passing):
The first commit modifies the AllowedArgs class, and defines arguments for the bitcoin-tx executable. You can look at this commit alone to understand the AllowedArg class and how it is used.
The second commit adds argument definitions for all the remaining executables (bitcoind, bitcoin-qt and bitcoin-cli). In addition, it moves several constants into .h files so that they can be accessed from the AllowedArgs class.
Note that the AllowedArgs class does not always have access to instances of the CChainParams class (since they are in different compilation units, which aren't always linked together). For this reason, I had to make new constants for
In addition, the help documentation for
In order to verify that none of the help documentation has been inadvertently modified by this change, I have
I ran that command for all 4 executables, with and without the
The help documentation for all executables is the same, with the exception of a few intentional changes:
A note on backward compatibility: this change will cause the executables to print an error message and immediately quit if there are any invalid command-line arguments or argument values. This has the potential to break things for users when they upgrade if they launch with invalid command-line options or if they have invalid options in their config file.
For example, a user might launch with
The Teamcity Continues integration system found some errors.
The basic linux-debian build went fine, the unit tests and rpc tests also finished Ok for that build.
Linux 32-bit and 64-bit compiles gave the same error;
MacOs compile (uses clang)
Compile on ARM;
referenced this pull request
Apr 22, 2017
The default value in the help message only applies if the command-line flag is not specified at all. If the command-line flag is specified for a requiredInt, then it must have a value that is an int. For example:
For the optionalBool types, the user can omit the value of the flag in order to indicate a value of true. For example: