57 {
"parameters", {
"Reset parameters",
"Resetting parameters", 0xAA}},
58 {
"network", {
"Reset network parameters",
"Resetting parameters", 0xBB}},
59 {
"all", {
"Reset parameters and network parameters",
"Resetting all", 0xFF}},
60 {
"switch-partition", {
"Switch partition",
"Switching partition", 0xCC}}
63 static void printHelp(std::ostream &os,
const std::string &command)
66 os << command <<
" <operation> [<args>]\n";
68 os <<
"Available operations are:\n";
72 const int min_padding = 3;
73 const int padding = max_command_len + min_padding -
74 static_cast<int>(cmd.first.length());
75 os <<
" " << cmd.first;
76 os << std::string(static_cast<std::size_t>(padding),
' ');
77 os << cmd.second.description <<
'\n';
80 os <<
"Available arguments are:\n";
81 os <<
" -h, --help Show this help and exit\n";
82 os <<
" -f name=<name> Filter by name\n";
83 os <<
" -f serial=<serial> Filter by serial number\n";
84 os <<
" -f mac=<mac> Filter by MAC address\n";
85 os <<
" -f iface=<mac> Filter by interface name\n";
86 os <<
" -f model=<model> Filter by model name\n";
87 os <<
" -y Assume 'yes' for all queries\n";
90 int runReset(
const std::string &command,
int argc,
char **argv)
97 std::cerr <<
"No operation specified\n";
102 const std::string argv_0 = argv[0];
103 if (argv_0 ==
"-h" || argv_0 ==
"--help")
112 std::cout <<
"Invalid operation specified\n";
120 std::string p = argv[i++];
132 catch (
const std::invalid_argument &ex)
134 std::cerr << ex.what() << std::endl;
139 else if (p ==
"-h" || p ==
"--help")
146 std::cerr <<
"Invalid argument: " << p <<
'\n';
152 if (device_filter.mac.empty() &&
153 device_filter.name.empty() &&
154 device_filter.serial.empty())
156 std::cerr <<
"No filter set" << std::endl;
164 std::cout <<
"No device found" << std::endl;
168 std::cout << reset_command->second.action <<
" of the following devices:\n";
173 std::cout <<
"Are you sure? [y/N] ";
175 std::getline(std::cin, answer);
176 if (answer !=
"y" && answer !=
"Y")
178 std::cout <<
"Cancel" << std::endl;
183 for (
const auto &device : devices)
186 wol.
send({{0xEE, 0xEE, 0xEE, reset_command->second.id}});
189 std::cout <<
"Done" << std::endl;