From 18e6099230c3bfe23d4faeeae289554f127deb87 Mon Sep 17 00:00:00 2001 From: gramanas Date: Fri, 19 Oct 2018 13:06:27 +0300 Subject: Add install script and config/verbose help --- CMakeLists.txt | 2 + README.html | 154 ++++++++++++++++++++++++++--------------------------- README.org | 6 +-- res/test-ck | 2 +- src/actionhelper.c | 21 ++++++++ src/actionhelper.h | 3 ++ src/actionparser.c | 2 +- src/actions.c | 10 ++++ tests/00_init | 2 +- tests/01_add | 2 +- tests/02_list | 4 +- tests/03_delete | 14 ++--- tests/04_search | 2 +- 13 files changed, 126 insertions(+), 98 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1709ba4..78a3ab7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,6 +98,8 @@ add_executable(ck ${ckBin_src}) target_link_libraries(ck ckLib) target_link_libraries(ck ${SQLITE3_LIBRARIES}) +install(TARGETS ck DESTINATION bin) + if (CK_TESTS) ## unit test add_executable(ck-test ${ckUnitTest_src}) diff --git a/README.html b/README.html index 43d1e52..9bbb656 100644 --- a/README.html +++ b/README.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + @@ -232,35 +232,35 @@ for the JavaScript code in this tag.

Table of Contents

-
-

ck

-
+
+

ck

+

The Config Keeper

-
-

build it

-
+
+

build it

+
-
-

requirements

-
+
+

requirements

+
  • clang (llvm) or gcc (gnu)
  • cmake
  • @@ -293,9 +293,9 @@ for the JavaScript code in this tag.
-
-

compiler

-
+
+

compiler

+
> export CC=clang
 # or
@@ -305,9 +305,9 @@ for the JavaScript code in this tag.
 
-
-

make

-
+
+

make

+
# clone the repo
 > cd ~/code; git clone https://gitlab.com/grm-grm/ck
@@ -325,13 +325,13 @@ for the JavaScript code in this tag.
 
-
-

for devs

-
+
+

for devs

+
-
-

CMake options

-
+
+

CMake options

+

cmake accepts the following options:

@@ -371,9 +371,9 @@ llvm has better asan than gcc, so I use that.
-
-

tests

-
+
+

tests

+

The testing "suite" is a bash script that runs regression and unit tests. Regression tests are under the tests/ directory @@ -382,9 +382,9 @@ under unit/ directory and test the code.

-
-

run tests

-
+
+

run tests

+

First make sure you build ck with the -DCK_TESTS=1 option. Then go to the build directory and type: @@ -396,9 +396,9 @@ go to the build directory and type:

-
-

test suite

-
+
+

test suite

+
$ ./test-ck -h
 ck test suite
@@ -416,9 +416,9 @@ flags:
 
-
-

manual

-
+
+

manual

+

ck's goal is to assist with the configuration file management. To that end it tries to provides a cli interface that is pretty straight-forward @@ -469,9 +469,9 @@ of flags one has to pass to ck.

-
-

ck configuration

-
+
+

ck configuration

+

ck uses sqlite to index the configuration files. The init action creates a .ck directory (under $HOME) @@ -486,7 +486,7 @@ each.

-Using the special keyword config (or conf or c or -c) you can set the path +Using the special keyword config (or -c) you can set the path in which ck will search for the .ck directory.

@@ -503,23 +503,19 @@ Usage: # /someplace/else must exist or # the action following it must be init -$ ck conf /someplace/else ... - -# same thing -$ ck c /someplace/else ... $ ck -c /someplace/else ...
-
-

Actions

-
+
+

Actions

+
-
-

init

-
+
+

init

+

or i or -i

@@ -549,9 +545,9 @@ $ ck init /path_to/where_you_want/your_configs/to_be -

add

-
+
+

add

+

or a or -a

@@ -592,9 +588,9 @@ $ ck add program_name config_path [-s] [-p]
-
-

list

-
+
+

list

+

or ls or l or -l

@@ -657,9 +653,9 @@ $ ck -l ckconf
-
-

search

-
+
+

search

+

or grep or s or -s

@@ -708,9 +704,9 @@ $ for i ($(ck ls paths)) grep -E 'A|B' $
-
-

edit

-
+
+

edit

+

or e or -e

@@ -759,7 +755,7 @@ $ ck edit emacs accounts.el
-

Created: 2018-10-14 Sun 15:34

+

Created: 2018-10-19 Fri 13:06

Validate

diff --git a/README.org b/README.org index b7da351..40c8a94 100644 --- a/README.org +++ b/README.org @@ -137,7 +137,7 @@ sqlite db. One can have multiple config directories with different configurations each. -Using the special keyword *config* (or *conf* or *c* or *-c*) you can set the path +Using the special keyword *config* (or *-c*) you can set the path in which ck will search for the *.ck* directory. You can prefix every action with this and ck will use the configuration @@ -149,10 +149,6 @@ Usage: # /someplace/else must exist or # the action following it must be init - $ ck conf /someplace/else ... - - # same thing - $ ck c /someplace/else ... $ ck -c /someplace/else ... #+END_SRC diff --git a/res/test-ck b/res/test-ck index 423d3bd..b1fd51e 100755 --- a/res/test-ck +++ b/res/test-ck @@ -15,7 +15,7 @@ function init { mkdir -p $TEST_LOCATION/vc mkdir $TEST_LOCATION/sec - exec $BIN/ck conf $BIN init $TEST_LOCATION/vc $TEST_LOCATION/sec > /dev/null & + exec $BIN/ck -c $BIN init $TEST_LOCATION/vc $TEST_LOCATION/sec > /dev/null & wait $! } diff --git a/src/actionhelper.c b/src/actionhelper.c index 6507e7b..6e76b2b 100644 --- a/src/actionhelper.c +++ b/src/actionhelper.c @@ -398,3 +398,24 @@ void print_HELP_help() { ckhelp("Note:\nRunning ck without arguments will print all the available actions."); report_help(); } + +void print_conf_help(void) { + ckhelp("Set a different ck configuration directory.\n"); + ckhelp("This has to be passed before any action or action argument"); + ckhelp("and after verbose (if set).\n"); + ckhelp("Usage:"); + ckhelp(" ck -c /path/to/conf ..."); + ckhelp(" ck config /path/to/conf ...\n"); + ckhelp("ck will use the database and config file in the path supplied"); + ckhelp("to perform any actions.\n"); + ckhelp("Tip:\nYou can alias `ck -c /path/to/conf` and use the new alias"); + ckhelp("to organise a different set of configurations, or some custom scrpits."); + report_help(); +} + +void print_verbose_help(void) { + ckhelp("WIP\n"); + ckhelp("Currently passing the verbose flag, prints a log of what ck is doing"); + ckhelp("during excecution of an action."); + report_help(); +} diff --git a/src/actionhelper.h b/src/actionhelper.h index eb544ce..bfe0b85 100644 --- a/src/actionhelper.h +++ b/src/actionhelper.h @@ -62,4 +62,7 @@ extern ListOpt list_make_options(cklist *args); CK_ACTIONS #undef X +extern void print_conf_help(void); +extern void print_verbose_help(void); + #endif /* ACTIONHELPER_H */ diff --git a/src/actionparser.c b/src/actionparser.c index aee9732..7ee46fe 100644 --- a/src/actionparser.c +++ b/src/actionparser.c @@ -24,7 +24,7 @@ const char* const strEDIT[] = {"3", "edit", "e", "-e"}; const char* const strLIST[] = {"5", "list", "ls", "l", "-l", "-ls"}; const char* const strSEARCH[] = {"4", "search", "grep", "s", "-s"}; const char* const strHELP[] = {"5", "help", "h", "-?", "-h", "--help"}; -const char* const strConfDir[] = {"4", "config", "conf", "c", "-c"}; +const char* const strConfDir[] = {"2", "config", "-c"}; const char* const strVersion[] = {"2", "version", "--version"}; const char* const strVerbose1[] = {"2", "--verbose", "-v"}; const char* const strVerbose2[] = {"2", "--Verbose", "-V"}; diff --git a/src/actions.c b/src/actions.c index 417f9ce..fcdf308 100644 --- a/src/actions.c +++ b/src/actions.c @@ -281,6 +281,16 @@ int run_HELP(UserOpt *opt, Conf *conf) { return 0; } + if (strcmp(list_get(opt->args), "config") == 0) { + print_conf_help(); + return 0; + } + + if (strcmp(list_get(opt->args), "verbose") == 0) { + print_verbose_help(); + return 0; + } + switch(parser_get_action(list_get(opt->args), NULL)) { #define X(ACTION) \ case CKA_##ACTION: \ diff --git a/tests/00_init b/tests/00_init index 9ea2f1c..1f3f2a6 100644 --- a/tests/00_init +++ b/tests/00_init @@ -5,7 +5,7 @@ running init mkdir -p $TEST_LOCATION/vc mkdir $TEST_LOCATION/sec -exec $BIN/ck conf $BIN init $TEST_LOCATION/vc $TEST_LOCATION/sec > /dev/null & +exec $BIN/ck -c $BIN init $TEST_LOCATION/vc $TEST_LOCATION/sec > /dev/null & wait $! if [ $? -ne 0 ]; then diff --git a/tests/01_add b/tests/01_add index 74c9558..1de64bf 100644 --- a/tests/01_add +++ b/tests/01_add @@ -9,7 +9,7 @@ echo "Test 3" > $BIN/test3.conf function run_add { # add configs to ck - exec $BIN/ck conf $BIN add $1 $BIN/$2 $3 $4 > /dev/null & + exec $BIN/ck -c $BIN add $1 $BIN/$2 $3 $4 > /dev/null & wait $! if [ $? -ne 0 ]; then diff --git a/tests/02_list b/tests/02_list index 35bf1ee..e330dad 100644 --- a/tests/02_list +++ b/tests/02_list @@ -11,13 +11,13 @@ add_config prog1 $path1 add_config prog2 $path2 add_config prog3 $path3 -for i in $($BIN/ck conf $BIN list paths); do +for i in $($BIN/ck -c $BIN list paths); do if [[ "$i" != "$path1" ]] && [[ "$i" != "$path2" ]] && [[ "$i" != "$path3" ]]; then err "Listing paths" fi done -for i in $($BIN/ck conf $BIN list programs); do +for i in $($BIN/ck -c $BIN list programs); do if [[ "$i" != "prog1" ]] && [[ "$i" != "prog2" ]] && [[ "$i" != "prog3" ]]; then err "Listing programs" fi diff --git a/tests/03_delete b/tests/03_delete index ee1cdd6..1668576 100644 --- a/tests/03_delete +++ b/tests/03_delete @@ -15,10 +15,10 @@ add_config prog2 $path3 add_config prog2 $path4 # delete path1 -exec $BIN/ck conf $BIN del -c $path1 > /dev/null & +exec $BIN/ck -c $BIN del -c $path1 > /dev/null & wait $! -for i in $($BIN/ck conf $BIN list paths); do +for i in $($BIN/ck -c $BIN list paths); do if [[ "$i" == "$path1" ]]; then err "Couldn't delete path." exit 1 @@ -26,26 +26,26 @@ for i in $($BIN/ck conf $BIN list paths); do done # delete path2 (also prog1) -exec $BIN/ck conf $BIN del -c $path2 > /dev/null & +exec $BIN/ck -c $BIN del -c $path2 > /dev/null & wait $! -for i in $($BIN/ck conf $BIN list programs); do +for i in $($BIN/ck -c $BIN list programs); do if [[ "$i" == "prog1" ]]; then err "Removing all configs should delete the correspondig program." fi done # delete prog2 -exec $BIN/ck conf $BIN del prog2 > /dev/null & +exec $BIN/ck -c $BIN del prog2 > /dev/null & wait $! -for i in $($BIN/ck conf $BIN list paths); do +for i in $($BIN/ck -c $BIN list paths); do if [[ "$i" == "$path3" ]] || [[ "$i" == "$path4" ]]; then err "Removing the program should delete all it's configs." fi done -for i in $($BIN/ck conf $BIN list programs); do +for i in $($BIN/ck -c $BIN list programs); do if [[ "$i" == "prog1" ]]; then err "Couldn't remove program." fi diff --git a/tests/04_search b/tests/04_search index 9f3d2e5..c3600c1 100644 --- a/tests/04_search +++ b/tests/04_search @@ -14,7 +14,7 @@ add_config prog2 $path3 "search-term" add_config prog3 $path4 "search-term" # delete path1 -if [[ $($BIN/ck conf $BIN search search-term | wc -l) != 4 ]]; then +if [[ $($BIN/ck -c $BIN search search-term | wc -l) != 4 ]]; then err "search failed." fi -- cgit v1.2.3