Skip to content

Commit bb858ec

Browse files
authored
Merge pull request #1 from abranhe/1.0.1
Jump to 1.0.1
2 parents 93f7bb1 + 62e99d7 commit bb858ec

File tree

9 files changed

+83
-106
lines changed

9 files changed

+83
-106
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*.gcov
55
*.gcda
66
*.gcno
7-
binary
7+
os
88
test
99
example
10-
coverage
10+
deps/

.travis.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
language: c
2+
3+
services:
4+
- docker
5+
26
compiler:
3-
- clang
4-
- gcc
5-
script: make run-test
7+
- clang
8+
- gcc
9+
10+
before_install:
11+
- docker pull abranhe/clib
12+
- docker run -it -v $(pwd):/src -w /src abranhe/clib sh -c "clib install"
13+
14+
script: docker run -it -v $(pwd):/src -w /src abranhe/clib sh -c "make run-test"
15+
616
notifications:
7-
email: false
17+
email: false

cli.c

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,72 @@
77

88
#include <stdio.h>
99
#include <string.h>
10+
#include <stdlib.h>
1011
#include "os.h"
1112

12-
const char*
13-
show_help() {
14-
return "\n\
15-
Wanna know your operating system? - I know right :)\n\n\
16-
Usage:\n\n\
17-
$ os <flag> \n\n\
18-
Options:\n\n\
19-
-v, --version output version number\n\
20-
-h, --help output usage information\n\n\
21-
Example:\n\n\
22-
$ os\n\
23-
macOS\n\n";
13+
/*
14+
* os version.
15+
*/
16+
17+
#define VERSION "1.0.1"
18+
19+
/*
20+
* Output usage information.
21+
*/
22+
23+
void
24+
usage(void) {
25+
fprintf(stderr,
26+
"\n Usage: os [options]"
27+
"\n"
28+
"\n Options:"
29+
"\n"
30+
"\n -h, --help output help information"
31+
"\n -v, --version output os version"
32+
"\n"
33+
"\n Examples:"
34+
"\n"
35+
"\n $ os"
36+
"\n macOS"
37+
"\n"
38+
"\n"
39+
);
40+
exit(1);
2441
}
2542

26-
/* CLI. */
43+
/*
44+
* Output os version.
45+
*/
46+
47+
void
48+
version(void) {
49+
printf("%s\n", VERSION);
50+
exit(0);
51+
}
52+
53+
/*
54+
* CLI
55+
*/
56+
2757
int
2858
main(int argc, char **argv) {
2959
char *a = argv[1];
3060

3161
if (argc == 2) {
3262
if (!strcmp(a, "-v") || !strcmp(a, "--version")) {
33-
printf("%s", "1.0.0\n");
63+
version();
3464
return 0;
3565
}
3666

3767
if (!strcmp(a, "-h") || !strcmp(a, "--help")) {
38-
printf("%s", show_help());
68+
usage();
3969
return 0;
4070
}
4171
}
4272

4373
if (argc > 1) {
44-
fprintf(stderr, "\033[31mSee `--help` for details.\033[0m\n");
74+
fprintf(stderr,
75+
"\033[31mSee `--help` for details.\033[0m\n");
4576
return 1;
4677
}
4778

deps/os.c/os.c

Lines changed: 0 additions & 26 deletions
This file was deleted.

deps/os.c/os.h

Lines changed: 0 additions & 21 deletions
This file was deleted.

deps/os.c/package.json

Lines changed: 0 additions & 21 deletions
This file was deleted.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "os",
3-
"version": "1.0.0",
4-
"description": "Wanna know your operating system? - I know right :)",
3+
"version": "1.0.1",
4+
"description": "Wanna know your operating system?",
55
"license": "MIT",
66
"keywords": [
77
"operating-system",
@@ -16,7 +16,7 @@
1616
],
1717
"repo": "abranhe/os",
1818
"dependencies": {
19-
"abranhe/os.c": "1.0.2"
19+
"abranhe/os.c": "1.0.3"
2020
},
2121
"install": "make install"
2222
}

readme.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,17 @@ $ os --help
4040
You will get:
4141

4242
```
43-
Wanna know your operating system? - I know right :)
43+
Usage: os [options]
4444
45-
Usage:
45+
Options:
4646
47-
$ os <flag>
47+
-h, --help output help information
48+
-v, --version output os version
4849
49-
Options:
50+
Examples:
5051
51-
-v, --version output version number
52-
-h, --help output usage information
53-
54-
Example:
55-
56-
$ os
57-
macOS
52+
$ os
53+
macOS
5854
```
5955

6056
## Related

test.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ function assert {
1919

2020
describe "Help"
2121
./os --help > /dev/null 2>&1
22-
assert $? 0
22+
assert $? 1
2323

2424
describe "Help: short flag"
2525
./os -h > /dev/null 2>&1
26-
assert $? 0
26+
assert $? 1
2727

2828
describe "Version"
2929
./os --version > /dev/null 2>&1
@@ -37,6 +37,14 @@ describe "Execute: more than two arguments"
3737
./os foo bar baz > /dev/null 2>&1
3838
assert $? 1
3939

40+
describe "Execute: no arguments"
41+
./os > /dev/null 2>&1
42+
assert $? 0
43+
44+
describe "Execute: one argumet or flag"
45+
./os foo > /dev/null 2>&1
46+
assert $? 1
47+
4048
printf "\033[32m\n(✓) Passed $tests assertions without errors\033[0m\n"
4149

4250
exit 0

0 commit comments

Comments
 (0)