|
13 | 13 | */ |
14 | 14 | #include "fossil/code/app.h" |
15 | 15 | #include <unistd.h> |
16 | | -#include <string.h> |
17 | | -#include <stdbool.h> |
18 | 16 |
|
19 | | - |
20 | | -void show_commands(void) { |
21 | | - fossil_io_printf("{blue}Usage: fossil_app [OPTIONS]{reset}\n"); |
| 17 | +void show_commands(char* app_name) { |
| 18 | + fossil_io_printf("{blue}Usage: {cyan}%s{blue} <options>{reset}\n", app_name); |
22 | 19 | fossil_io_printf("{cyan} --help Show this help message{reset}\n"); |
23 | 20 | fossil_io_printf("{cyan} --version Show version information{reset}\n"); |
24 | 21 | fossil_io_printf("{cyan} color Enable colored output ({yellow}'enable'/disable/auto{cyan}){reset}\n"); |
25 | | - exit(0); |
| 22 | + exit(FOSSIL_IO_SUCCESS); |
26 | 23 | } |
27 | 24 |
|
28 | 25 | void show_version(void) { |
29 | 26 | fossil_io_printf("{blue}%s version %s{reset}\n", FOSSIL_APP_NAME, FOSSIL_APP_VERSION); |
30 | | - exit(0); |
| 27 | + exit(FOSSIL_IO_SUCCESS); |
31 | 28 | } |
32 | 29 |
|
33 | 30 | bool app_entry(int argc, char** argv) { |
34 | | - for (int i = 1; i < argc; ++i) { |
35 | | - if (argv[i] == NULL) continue; |
36 | | - if (strcmp(argv[i], "--help") == 0) { |
37 | | - show_commands(); |
38 | | - } else if (strcmp(argv[i], "--version") == 0) { |
| 31 | + for (u32 i = 1; i < argc; ++i) { |
| 32 | + if (argv[i] == cnullptr) continue; |
| 33 | + if (fossil_io_cstring_compare(argv[i], "--help") == 0) { |
| 34 | + show_commands(argv[0]); |
| 35 | + } else if (fossil_io_cstring_compare(argv[i], "--version") == 0) { |
39 | 36 | show_version(); |
40 | | - } else if (strcmp(argv[i], "color") == 0) { |
41 | | - if (i + 1 < argc && argv[i + 1] != NULL) { |
42 | | - if (strcmp(argv[i + 1], "enable") == 0) { |
| 37 | + } else if (fossil_io_cstring_compare(argv[i], "color") == 0) { |
| 38 | + if (i + 1 < argc && argv[i + 1] != cnullptr) { |
| 39 | + if (fossil_io_cstring_compare(argv[i + 1], "enable") == 0) { |
43 | 40 | FOSSIL_IO_COLOR_ENABLE = true; |
44 | | - } else if (strcmp(argv[i + 1], "disable") == 0) { |
| 41 | + } else if (fossil_io_cstring_compare(argv[i + 1], "disable") == 0) { |
45 | 42 | FOSSIL_IO_COLOR_ENABLE = false; |
46 | | - } else if (strcmp(argv[i + 1], "auto") == 0) { |
| 43 | + } else if (fossil_io_cstring_compare(argv[i + 1], "auto") == 0) { |
47 | 44 | FOSSIL_IO_COLOR_ENABLE = isatty(STDOUT_FILENO); |
48 | 45 | } |
49 | 46 | ++i; // Skip next argument |
|
0 commit comments