diff options
Diffstat (limited to 'src/cfetch.c')
| -rw-r--r-- | src/cfetch.c | 61 |
1 files changed, 59 insertions, 2 deletions
diff --git a/src/cfetch.c b/src/cfetch.c index fd53ae5..c0ea8ab 100644 --- a/src/cfetch.c +++ b/src/cfetch.c @@ -24,12 +24,21 @@ #include <unistd.h> #include <stddef.h> +#define COMMAND(large, small) \ + (!strcmp(argv[i], large) || !strcmp(argv[i], small)) + +void parse_args(int argc, char** argv); +void print_help(); + +int main(int argc, char **argv) +{ + parse_args(argc, argv); + -int main(void) { struct system_info_t info = { 0 }; //info.debug = 1; // set default artwork - info.ascii_art = 0; + info.ascii_art = 3; // set systeminformation // use // to uncomment or comment @@ -54,3 +63,51 @@ int main(void) { get_gpu get_colours ? */ + +void parse_cmd(int argc, char **argv) +{ + for (int i = 1; i < argc; i++) { + if (argv[i][0] != '-') + { + fprintf(stderr, + "Error: invalid option: \"%s\". An option must start with `-`\n", + argv[i]); + print_help(); + exit(1); + } + if (COMMAND("--help", "-h")) { + print_help(); + exit(1); + } + if (COMMAND("--version", "-v")) { + printf("cfetch version: 0.1.1\n"); + exit(0); + } else { + fprintf(stderr, + "Error: invalid option: \"%s\"\n", + argv[i]); + print_help(); + exit(1); + } + } + + return; +} + +void parse_args(int argc, char **argv) +{ + if (argc == 1) { + return; + } + + parse_cmd(argc, argv); + return; +} + +void print_help() +{ + printf("\ncfetch, the neofetch/commifetch clone!\n"); + printf("\nusage: cfetch\t [-v | --version] [-h | --help]\n"); + printf(" -v --version\t prints the current version of cfetch.\n"); + printf(" -h --help\t prints the helper menu of cfetch.\n"); +} |
