int run(int argc, const char * const *argv) const;
private:
+ void usage(std::ostream& os) const;
+
+private:
const std::string _name;
std::map<std::string, std::unique_ptr<Command>> _commands;
};
if (argc < 1)
{
std::cerr << "ERROR: COMMAND is not provided" << std::endl;
- std::cerr << std::endl;
- std::cerr << "USAGE: " << _name << " [COMMAND] ..." << std::endl;
+ usage(std::cerr);
return 255;
}
if (it == _commands.end())
{
std::cerr << "ERROR: '" << command << "' is not a valid command" << std::endl;
- std::cerr << std::endl;
- std::cerr << "USAGE: " << _name << " [COMMAND] ..." << std::endl;
- std::cerr << std::endl;
- std::cerr << "SUPPORTED COMMANDS:" << std::endl;
- for (auto it = _commands.begin(); it != _commands.end(); ++it)
- {
- std::cerr << " " << it->first << std::endl;
- }
+ usage(std::cerr);
return 255;
}
return it->second->run(argc - 1, argv + 1);
}
+void App::usage(std::ostream& os) const
+{
+ os << std::endl;
+ os << "USAGE: " << _name << " [COMMAND] ..." << std::endl;
+ os << std::endl;
+ os << "SUPPORTED COMMANDS:" << std::endl;
+ for (auto it = _commands.begin(); it != _commands.end(); ++it)
+ {
+ os << " " << it->first << std::endl;
+ }
+}
+
} // namespace cli