|
7 | 7 | #include <winrt/Windows.Foundation.Collections.h>
|
8 | 8 | #include <cstring>
|
9 | 9 | #include <string>
|
| 10 | +#include <tchar.h> |
| 11 | +#include "arg.inl" |
10 | 12 |
|
11 | 13 | namespace winrt
|
12 | 14 | {
|
@@ -99,17 +101,33 @@ int wmain(const int argc, const wchar_t* argv[])
|
99 | 101 | return 1;
|
100 | 102 | }
|
101 | 103 |
|
102 |
| - if (argc <= 1) |
| 104 | + arginit(argc, argv, L"Show and select clipboard history"); |
| 105 | + |
| 106 | + argoptional(); |
| 107 | + const TCHAR* cmd = argnumdesc(1, nullptr, L"command", L"Command option: list, view or select"); |
| 108 | + const TCHAR* item = argnumdesc(2, nullptr, L"clip_id", L"Clip item target"); |
| 109 | + |
| 110 | + if (!argcleanup()) |
| 111 | + return EXIT_FAILURE; |
| 112 | + if (argusage()) |
| 113 | + return EXIT_SUCCESS; |
| 114 | + |
| 115 | + if (cmd == nullptr || _wcsicmp(cmd, L"list") == 0) |
103 | 116 | DumpClipboardHistoryAsync().get();
|
104 |
| - else if (_wcsicmp(argv[1], L"view") == 0) |
105 |
| - DumpClipboardHistoryItemAsync(argv[2]).get(); |
106 |
| - else if (_wcsicmp(argv[1], L"select") == 0) |
107 |
| - SelectClipboardHistoryItemAsync(argv[2]).get(); |
| 117 | + else if (item == nullptr) |
| 118 | + { |
| 119 | + fwprintf(stderr, L"Error: Clip id missing\n"); |
| 120 | + return EXIT_FAILURE; |
| 121 | + } |
| 122 | + else if (_wcsicmp(cmd, L"view") == 0) |
| 123 | + DumpClipboardHistoryItemAsync(item).get(); |
| 124 | + else if (_wcsicmp(cmd, L"select") == 0) |
| 125 | + SelectClipboardHistoryItemAsync(item).get(); |
108 | 126 | else
|
109 | 127 | {
|
110 |
| - fwprintf(stderr, L"Unknown option.\n"); |
111 |
| - return 1; |
| 128 | + fwprintf(stderr, L"Error: Unknown command: %s\n", cmd); |
| 129 | + return EXIT_FAILURE; |
112 | 130 | }
|
113 | 131 |
|
114 |
| - return 0; |
| 132 | + return EXIT_SUCCESS; |
115 | 133 | }
|
0 commit comments