diff options
author | Simon Warta <[email protected]> | 2015-12-12 00:40:40 +0100 |
---|---|---|
committer | Simon Warta <[email protected]> | 2015-12-12 00:40:40 +0100 |
commit | b457eb9fa218598dd25ccaaa62e4983871cff9bd (patch) | |
tree | 13465538b70685a77143a64ebf942de4055360a2 /src/cli | |
parent | 9eaf1b166ff0e99172ccccfea5d6c04adb49b46e (diff) |
Improve some argument checks and usage messages of cli apps
See also #354
Diffstat (limited to 'src/cli')
-rw-r--r-- | src/cli/ca.cpp | 5 | ||||
-rw-r--r-- | src/cli/cert_verify.cpp | 5 | ||||
-rw-r--r-- | src/cli/compress.cpp | 2 | ||||
-rw-r--r-- | src/cli/dsa_ver.cpp | 5 | ||||
-rw-r--r-- | src/cli/factor.cpp | 2 | ||||
-rw-r--r-- | src/cli/getopt.cpp | 8 | ||||
-rw-r--r-- | src/cli/hash.cpp | 2 | ||||
-rw-r--r-- | src/cli/pkcs10.cpp | 4 | ||||
-rw-r--r-- | src/cli/prime.cpp | 4 | ||||
-rw-r--r-- | src/cli/rng.cpp | 2 | ||||
-rw-r--r-- | src/cli/self_sig.cpp | 4 | ||||
-rw-r--r-- | src/cli/x509print.cpp | 2 |
12 files changed, 27 insertions, 18 deletions
diff --git a/src/cli/ca.cpp b/src/cli/ca.cpp index fb6d9582a..c62b4f231 100644 --- a/src/cli/ca.cpp +++ b/src/cli/ca.cpp @@ -19,8 +19,9 @@ int ca(const std::vector<std::string> &args) if(args.size() != 5) { - std::cout << "Usage: " << args[0] << " <passphrase> " - << "<ca cert> <ca key> <pkcs10>" << std::endl; + std::cout << "Usage: " << args[0] << " " + << "passphrase ca_cert ca_key pkcs10" + << std::endl; return 1; } diff --git a/src/cli/cert_verify.cpp b/src/cli/cert_verify.cpp index 7a1bec983..7e03c81ab 100644 --- a/src/cli/cert_verify.cpp +++ b/src/cli/cert_verify.cpp @@ -17,9 +17,10 @@ int cert_verify(const std::vector<std::string> &args) { using namespace Botan; - if(args.size() <= 2) + if(args.size() < 3) { - std::cout << "Usage: " << args[0] << " subject.pem [CA certificates...]" << std::endl; + std::cout << "Usage: " << args[0] << " subject.pem CA_certificate [CA_certificate ...]" + << std::endl; return 1; } diff --git a/src/cli/compress.cpp b/src/cli/compress.cpp index 93bc76eb4..b0d0144d5 100644 --- a/src/cli/compress.cpp +++ b/src/cli/compress.cpp @@ -37,7 +37,7 @@ void do_compress(Transform& comp, std::ifstream& in, std::ostream& out) int compress(const std::vector<std::string> &args) { - if(args.size() != 2 && args.size() != 3 && args.size() != 4) + if(args.size() < 2 || args.size() > 4) { std::cout << "Usage: " << args[0] << " input [type] [level]" << std::endl; return 1; diff --git a/src/cli/dsa_ver.cpp b/src/cli/dsa_ver.cpp index 64d60a5cf..13f71b59d 100644 --- a/src/cli/dsa_ver.cpp +++ b/src/cli/dsa_ver.cpp @@ -21,8 +21,9 @@ int dsa_verify(const std::vector<std::string> &args) { if(args.size() != 4) { - std::cout << "Usage: " << args[0] - << " keyfile messagefile sigfile" << std::endl; + std::cout << "Usage: " << args[0] << " " + << "keyfile messagefile sigfile" + << std::endl; return 1; } diff --git a/src/cli/factor.cpp b/src/cli/factor.cpp index d2c0a2df5..52da46153 100644 --- a/src/cli/factor.cpp +++ b/src/cli/factor.cpp @@ -126,7 +126,7 @@ int factor(const std::vector<std::string> &args) { if(args.size() != 2) { - std::cout << "Usage: " << args[0] << " <integer>" << std::endl; + std::cout << "Usage: " << args[0] << " integer" << std::endl; return 1; } diff --git a/src/cli/getopt.cpp b/src/cli/getopt.cpp index 7b7e14932..fde3b5ce9 100644 --- a/src/cli/getopt.cpp +++ b/src/cli/getopt.cpp @@ -16,8 +16,14 @@ void OptionParser::parse(const std::vector<std::string> &args) { std::string arg = args[j]; + // FIXME: cli app must manually query if user requested help + // in order to be able to stop the cpp. At the moment e.g. + // `./botan keygen --help` generates keys. if(arg == "help" || arg == "--help" || arg == "-h") - return help(std::cout, appname); + { + help(std::cout, appname); + return; + } if(arg.size() > 2 && arg[0] == '-' && arg[1] == '-') { diff --git a/src/cli/hash.cpp b/src/cli/hash.cpp index 81a72ca17..9dd07d488 100644 --- a/src/cli/hash.cpp +++ b/src/cli/hash.cpp @@ -20,7 +20,7 @@ int hash(const std::vector<std::string> &args) { if(args.size() < 3) { - std::cout << "Usage: " << args[0] << " digest <filenames>" << std::endl; + std::cout << "Usage: " << args[0] << " algorithm filename [filename ...]" << std::endl; return 1; } diff --git a/src/cli/pkcs10.cpp b/src/cli/pkcs10.cpp index 106fe2c24..710020666 100644 --- a/src/cli/pkcs10.cpp +++ b/src/cli/pkcs10.cpp @@ -22,8 +22,8 @@ int pkcs10(const std::vector<std::string> &args) { if(args.size() != 6) { - std::cout << "Usage: " << args[0] - << " passphrase name country_code organization email" << std::endl; + std::cout << "Usage: " << args[0] << " " + << "passphrase name country_code organization email" << std::endl; return 1; } diff --git a/src/cli/prime.cpp b/src/cli/prime.cpp index 82efa75d2..c7c9d1ffe 100644 --- a/src/cli/prime.cpp +++ b/src/cli/prime.cpp @@ -17,9 +17,9 @@ namespace { int prime(const std::vector<std::string> &args) { - if(args.size() < 2) + if(args.size() < 2 || args.size() > 3) { - std::cout << "Usage: " << args[0] << " bits count" << std::endl; + std::cout << "Usage: " << args[0] << " bits [count]" << std::endl; return 1; } diff --git a/src/cli/rng.cpp b/src/cli/rng.cpp index 3fe8719ce..ef7b3dc6b 100644 --- a/src/cli/rng.cpp +++ b/src/cli/rng.cpp @@ -16,7 +16,7 @@ namespace { int rng(const std::vector<std::string> &args) { - if(args.size() == 1) + if(args.size() < 2 || args.size() > 3) { std::cout << "Usage: " << args[0] << " [--raw-entropy] n\n" << "n: number of bytes" diff --git a/src/cli/self_sig.cpp b/src/cli/self_sig.cpp index 2c43f7acc..dea18420e 100644 --- a/src/cli/self_sig.cpp +++ b/src/cli/self_sig.cpp @@ -22,8 +22,8 @@ int self_sig(const std::vector<std::string> &args) { if(args.size() != 7) { - std::cout << "Usage: " << args[0] - << " passphrase [CA|user] name country_code organization email" + std::cout << "Usage: " << args[0] << " " + << "passphrase [CA|user] name country_code organization email" << std::endl; return 1; } diff --git a/src/cli/x509print.cpp b/src/cli/x509print.cpp index e583c91c2..5c069ca77 100644 --- a/src/cli/x509print.cpp +++ b/src/cli/x509print.cpp @@ -12,7 +12,7 @@ namespace { int x509print(const std::vector<std::string> &args) { - if(args.size() != 1) + if(args.size() != 2) { std::cout << "Usage: " << args[0] << " cert.pem" << std::endl; return 1; |