53   std::function<int(
const std::string &, 
int, 
char **)> 
fun;
 
   56 static const std::map<std::string, Command> 
commands =
 
   60         {
"forceip", {
"Temporarily set the IP of a device", 
runForceIP}},
 
   61         {
"reset", {
"Reset a device's parameters", 
runReset}}
 
   71       WSAStartup(MAKEWORD(2, 2), &wsaData);
 
   83 int main(
int argc, 
char *argv[])
 
   87   std::string help_string = std::string(
"Usage: ") +
 
   88       argv[0] + 
" [-h | --help] [--version] <command> [<args>]\n\n" +
 
   89       "Available commands are:\n";
 
   94     const int min_padding = 3;
 
   96         max_command_len + min_padding - 
static_cast<int>(cmd.first.length());
 
   97     help_string += 
"    " + cmd.first +
 
   98                    std::string(
static_cast<std::size_t
>(padding), 
' ') +
 
   99                    cmd.second.description + 
"\n";
 
  102   help_string += std::string(
"\n") +
 
  103       "If no command is given, 'ls' is assumed.\n" +
 
  104       "See '" + argv[0] + 
" <command> --help' for command-specific help.";
 
  108   int argc_subcommand = argc - 1;
 
  109   char **argv_subcommand = argv + 1;
 
  113     const std::string argv_1(argv[1]);
 
  114     if (argv_1 == 
"--help" || argv_1 == 
"-h")
 
  116       std::cout << help_string << std::endl;
 
  119     if (argv_1 == 
"--version")
 
  121       std::cout << PACKAGE_VERSION << std::endl;
 
  125     if (!argv_1.empty() && argv_1[0] != 
'-')
 
  135     std::cerr << 
"Invalid command\n";
 
  136     std::cerr << help_string << 
'\n';
 
  140   std::string command_str;
 
  141   for (
int i = 0; i < (argc - argc_subcommand); ++i)
 
  143     if (!command_str.empty())
 
  144     { command_str += 
' '; }
 
  145     command_str += argv[i];
 
  148   return command->second.fun(command_str, argc_subcommand, argv_subcommand);