-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.c
81 lines (68 loc) · 1.07 KB
/
cli.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//
// cli.c
//
// MIT licensed.
// Copyright (c) Abraham Hernandez <abraham@abranhe.com>
//
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "os.h"
/*
* os version.
*/
#define VERSION "1.0.1"
/*
* Output usage information.
*/
void
usage(void) {
fprintf(stderr,
"\n Usage: os [options]"
"\n"
"\n Options:"
"\n"
"\n -h, --help output help information"
"\n -v, --version output os version"
"\n"
"\n Examples:"
"\n"
"\n $ os"
"\n macOS"
"\n"
"\n"
);
exit(1);
}
/*
* Output os version.
*/
void
version(void) {
printf("%s\n", VERSION);
exit(0);
}
/*
* CLI
*/
int
main(int argc, char **argv) {
char *a = argv[1];
if (argc == 2) {
if (!strcmp(a, "-v") || !strcmp(a, "--version")) {
version();
return 0;
}
if (!strcmp(a, "-h") || !strcmp(a, "--help")) {
usage();
return 0;
}
}
if (argc > 1) {
fprintf(stderr,
"\033[31mSee `--help` for details.\033[0m\n");
return 1;
}
printf("%s\n", operating_system());
return 0;
}