Skip to content

Commit

Permalink
Merge pull request #1 from abranhe/1.0.1
Browse files Browse the repository at this point in the history
Jump to 1.0.1
  • Loading branch information
abranhe authored Jan 26, 2019
2 parents 93f7bb1 + 62e99d7 commit bb858ec
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 106 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*.gcov
*.gcda
*.gcno
binary
os
test
example
coverage
deps/
18 changes: 14 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
language: c

services:
- docker

compiler:
- clang
- gcc
script: make run-test
- clang
- gcc

before_install:
- docker pull abranhe/clib
- docker run -it -v $(pwd):/src -w /src abranhe/clib sh -c "clib install"

script: docker run -it -v $(pwd):/src -w /src abranhe/clib sh -c "make run-test"

notifications:
email: false
email: false
63 changes: 47 additions & 16 deletions cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,72 @@

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "os.h"

const char*
show_help() {
return "\n\
Wanna know your operating system? - I know right :)\n\n\
Usage:\n\n\
$ os <flag> \n\n\
Options:\n\n\
-v, --version output version number\n\
-h, --help output usage information\n\n\
Example:\n\n\
$ os\n\
macOS\n\n";
/*
* 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);
}

/* CLI. */
/*
* 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")) {
printf("%s", "1.0.0\n");
version();
return 0;
}

if (!strcmp(a, "-h") || !strcmp(a, "--help")) {
printf("%s", show_help());
usage();
return 0;
}
}

if (argc > 1) {
fprintf(stderr, "\033[31mSee `--help` for details.\033[0m\n");
fprintf(stderr,
"\033[31mSee `--help` for details.\033[0m\n");
return 1;
}

Expand Down
26 changes: 0 additions & 26 deletions deps/os.c/os.c

This file was deleted.

21 changes: 0 additions & 21 deletions deps/os.c/os.h

This file was deleted.

21 changes: 0 additions & 21 deletions deps/os.c/package.json

This file was deleted.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "os",
"version": "1.0.0",
"description": "Wanna know your operating system? - I know right :)",
"version": "1.0.1",
"description": "Wanna know your operating system?",
"license": "MIT",
"keywords": [
"operating-system",
Expand All @@ -16,7 +16,7 @@
],
"repo": "abranhe/os",
"dependencies": {
"abranhe/os.c": "1.0.2"
"abranhe/os.c": "1.0.3"
},
"install": "make install"
}
18 changes: 7 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,17 @@ $ os --help
You will get:

```
Wanna know your operating system? - I know right :)
Usage: os [options]
Usage:
Options:
$ os <flag>
-h, --help output help information
-v, --version output os version
Options:
Examples:
-v, --version output version number
-h, --help output usage information
Example:
$ os
macOS
$ os
macOS
```

## Related
Expand Down
12 changes: 10 additions & 2 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ function assert {

describe "Help"
./os --help > /dev/null 2>&1
assert $? 0
assert $? 1

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

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

describe "Execute: no arguments"
./os > /dev/null 2>&1
assert $? 0

describe "Execute: one argumet or flag"
./os foo > /dev/null 2>&1
assert $? 1

printf "\033[32m\n(✓) Passed $tests assertions without errors\033[0m\n"

exit 0

0 comments on commit bb858ec

Please sign in to comment.