| 44 | } |
| 45 | |
| 46 | static int parseArguments(int ac, WCHAR **av, po::variables_map& vm, printInfoStruct& printInfo) |
| 47 | { |
| 48 | WCHAR namePath[MAX_PATH]; |
| 49 | GetModuleFileName(NULL, namePath, MAX_PATH); |
| 50 | WCHAR *progName = PathFindFileName(namePath); |
| 51 | |
| 52 | po::options_description desc; |
| 53 | |
| 54 | desc.add_options() |
| 55 | ("help,h", "Print help message and exit") |
| 56 | ("version,V", "Print version and exit") |
| 57 | ("debug,d", "Verbose/Debug output") |
| 58 | ("warning,w", po::wvalue<std::wstring>(), "Warning threshold") |
| 59 | ("critical,c", po::wvalue<std::wstring>(), "Critical threshold") |
| 60 | ("unit,u", po::wvalue<std::wstring>(), "The unit to use for display (default MB)") |
| 61 | ("show-used,U", "Show used swap instead of the free swap") |
| 62 | ; |
| 63 | |
| 64 | po::wcommand_line_parser parser(ac, av); |
| 65 | |
| 66 | try { |
| 67 | po::store( |
| 68 | parser |
| 69 | .options(desc) |
| 70 | .style( |
| 71 | po::command_line_style::unix_style | |
| 72 | po::command_line_style::allow_long_disguise) |
| 73 | .run(), |
| 74 | vm); |
| 75 | vm.notify(); |
| 76 | } catch (const std::exception& e) { |
| 77 | std::cout << e.what() << '\n' << desc << '\n'; |
| 78 | return 3; |
| 79 | } |
| 80 | |
| 81 | if (vm.count("help")) { |
| 82 | std::wcout << progName << " Help\n\tVersion: " << VERSION << '\n'; |
| 83 | wprintf( |
| 84 | L"%s is a simple program to check a machines swap in percent.\n" |
| 85 | L"You can use the following options to define its behaviour:\n\n", progName); |
| 86 | std::cout << desc; |
| 87 | wprintf( |
| 88 | L"\nIt will then output a string looking something like this:\n\n" |
| 89 | L"\tSWAP WARNING - 20%% free | swap=2000B;3000;500;0;10000\n\n" |
| 90 | L"\"SWAP\" being the type of the check, \"WARNING\" the returned status\n" |
| 91 | L"and \"20%%\" is the returned value.\n" |
| 92 | L"The performance data is found behind the \"|\", in order:\n" |
| 93 | L"returned value, warning threshold, critical threshold, minimal value and,\n" |
| 94 | L"if applicable, the maximal value. Performance data will only be displayed when\n" |
| 95 | L"you set at least one threshold\n\n" |
| 96 | L"%s' exit codes denote the following:\n" |
| 97 | L" 0\tOK,\n\tNo Thresholds were broken or the programs check part was not executed\n" |
| 98 | L" 1\tWARNING,\n\tThe warning, but not the critical threshold was broken\n" |
| 99 | L" 2\tCRITICAL,\n\tThe critical threshold was broken\n" |
| 100 | L" 3\tUNKNOWN, \n\tThe program experienced an internal or input error\n\n" |
| 101 | L"Threshold syntax:\n\n" |
| 102 | L"-w THRESHOLD\n" |
| 103 | L"warn if threshold is broken, which means VALUE > THRESHOLD\n" |