/* * (C) 2009,2014,2015 Jack Lloyd * * Botan is released under the Simplified BSD License (see license.txt) */ #include "cli.h" #include #include #include #include namespace { std::string main_help() { const std::set avail_commands = Botan::map_keys_as_set(Botan_CLI::Command::global_registry()); std::ostringstream oss; oss << "Usage: botan \n"; oss << "Available commands: "; std::copy(avail_commands.begin(), avail_commands.end(), std::ostream_iterator(oss, " ")); oss << "\n"; return oss.str(); } } int main(int argc, char* argv[]) { std::cerr << Botan::runtime_version_check(BOTAN_VERSION_MAJOR, BOTAN_VERSION_MINOR, BOTAN_VERSION_PATCH); const std::string cmd_name = (argc <= 1) ? "help" : argv[1]; if(cmd_name == "help" || cmd_name == "--help") { std::cout << main_help(); return 1; } Botan_CLI::Command* cmd = Botan_CLI::Command::get_cmd(cmd_name); if(!cmd) { std::cout << "Unknown command " << cmd_name << " (try --help)\n"; return 1; } std::vector args(argv + 2, argv + argc); return cmd->run(args); }