Fix style in -stdin and -stdinrpcpass handling

This commit is contained in:
João Barbosa 2017-08-24 18:35:06 +01:00
parent 66a5b419ef
commit 7696841329

View file

@ -296,19 +296,22 @@ int CommandLineRPC(int argc, char *argv[])
} }
std::string rpcPass; std::string rpcPass;
if (gArgs.GetBoolArg("-stdinrpcpass", false)) { if (gArgs.GetBoolArg("-stdinrpcpass", false)) {
if(!std::getline(std::cin,rpcPass)) if (!std::getline(std::cin, rpcPass)) {
throw std::runtime_error("-stdinrpcpass specified but failed to read from standard input"); throw std::runtime_error("-stdinrpcpass specified but failed to read from standard input");
}
gArgs.ForceSetArg("-rpcpassword", rpcPass); gArgs.ForceSetArg("-rpcpassword", rpcPass);
} }
std::vector<std::string> args = std::vector<std::string>(&argv[1], &argv[argc]); std::vector<std::string> args = std::vector<std::string>(&argv[1], &argv[argc]);
if (gArgs.GetBoolArg("-stdin", false)) { if (gArgs.GetBoolArg("-stdin", false)) {
// Read one arg per line from stdin and append // Read one arg per line from stdin and append
std::string line; std::string line;
while (std::getline(std::cin,line)) while (std::getline(std::cin, line)) {
args.push_back(line); args.push_back(line);
}
} }
if (args.size() < 1) if (args.size() < 1) {
throw std::runtime_error("too few parameters (need at least command)"); throw std::runtime_error("too few parameters (need at least command)");
}
std::string strMethod = args[0]; std::string strMethod = args[0];
args.erase(args.begin()); // Remove trailing method name from arguments vector args.erase(args.begin()); // Remove trailing method name from arguments vector