diff --git a/.gitignore b/.gitignore index b4b23c1..f4827a8 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ *.gcov *.gcda *.gcno -binary +os test example -coverage +deps/ \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 3cb95fa..26add4e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 \ No newline at end of file diff --git a/cli.c b/cli.c index 5ba6e47..ebf1974 100644 --- a/cli.c +++ b/cli.c @@ -7,41 +7,72 @@ #include #include +#include #include "os.h" -const char* -show_help() { - return "\n\ - Wanna know your operating system? - I know right :)\n\n\ - Usage:\n\n\ - $ os \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; } diff --git a/deps/os.c/os.c b/deps/os.c/os.c deleted file mode 100644 index eb05963..0000000 --- a/deps/os.c/os.c +++ /dev/null @@ -1,26 +0,0 @@ -// -// os.c -// Get to know your operating system -// -// MIT licensed. -// Copyright (c) Abraham Hernandez -// - -const char * operating_system() -{ - #ifdef _WIN32 - return "win32"; - #elif _WIN64 - return "win64"; - #elif __unix || __unix__ - return "unix"; - #elif __APPLE__ || __MACH__ - return "macOS"; - #elif __linux__ - return "linux"; - #elif __FreeBSD__ - return "freeBSD"; - #else - return "other"; - #endif -} diff --git a/deps/os.c/os.h b/deps/os.c/os.h deleted file mode 100644 index 5908921..0000000 --- a/deps/os.c/os.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef OS_H -#define OS_H - -// -// os.h -// -// MIT licensed. -// Copyright (c) Abraham Hernandez -// - -#ifdef __cplusplus -extern "C" { -#endif - -const char * operating_system(void); - -#ifdef __cplusplus -} -#endif - -#endif // OS_H diff --git a/deps/os.c/package.json b/deps/os.c/package.json deleted file mode 100644 index 49cb501..0000000 --- a/deps/os.c/package.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "os.c", - "version": "1.0.2", - "description": "Small C library to know your operating system", - "license": "MIT", - "keywords": [ - "os", - "macos", - "linux", - "windows", - "win32", - "win64", - "operating-system", - "tool" - ], - "repo": "abranhe/os.c", - "src": [ - "os.h", - "os.c" - ] -} diff --git a/package.json b/package.json index 0ec95ed..4a848aa 100644 --- a/package.json +++ b/package.json @@ -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", @@ -16,7 +16,7 @@ ], "repo": "abranhe/os", "dependencies": { - "abranhe/os.c": "1.0.2" + "abranhe/os.c": "1.0.3" }, "install": "make install" } diff --git a/readme.md b/readme.md index fa6cf42..46cee3d 100644 --- a/readme.md +++ b/readme.md @@ -40,21 +40,17 @@ $ os --help You will get: ``` -Wanna know your operating system? - I know right :) + Usage: os [options] - Usage: + Options: - $ os + -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 diff --git a/test.sh b/test.sh index f94fb56..9a83c39 100644 --- a/test.sh +++ b/test.sh @@ -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 @@ -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