aboutsummaryrefslogtreecommitdiffstats
path: root/src/actionhelper.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/actionhelper.c')
-rw-r--r--src/actionhelper.c144
1 files changed, 15 insertions, 129 deletions
diff --git a/src/actionhelper.c b/src/actionhelper.c
index c0dff0f..93b3107 100644
--- a/src/actionhelper.c
+++ b/src/actionhelper.c
@@ -85,33 +85,6 @@ AddOpt add_make_options(cklist *args) {
return addOpt;
}
-DelOpt del_make_options(cklist *args) {
- list_rewind(args);
- DelOpt delOpt = {
- .arg = NULL,
- .isConf = 0,
- .err = DEL_NO_ERR
- };
-
- if (strcmp(list_get(args), "-c") == 0) {
- delOpt.isConf = 1;
- if (!list_next(args)) {
- delOpt.err = DEL_ERR_WRONG_ARGS;
- return delOpt;
- }
- delOpt.arg = list_get(args);
- } else {
- delOpt.arg = list_get(args);
- if (list_next(args)) {
- delOpt.err = DEL_ERR_WRONG_ARGS;
- return delOpt;
- }
- }
-
- list_rewind(args);
- return delOpt;
-}
-
void add_print_opts(AddOpt *opt) {
printf("Program:\t%s\nConfig:\t\t%s\n", opt->progName, opt->confPath);
if (opt->prime && opt->secret) {
@@ -353,135 +326,48 @@ void print_RESTORE_result(int err) {
}
void print_INIT_help() {
- ckhelp("Initialize the database and create the file that holds");
- ckhelp("the paths where configurations will be stored.");
- ckhelp("Namely the version control and the secret directories.\n");
- ckhelp("It takes two arguments:");
- ckhelp(" `version_control_dir`: the path to the version control directory");
- ckhelp(" `secret_dir`: the path to the secret directory");
- report_help();
+ HELP("ck init VERSION_CONTROL_DIR SECRET_DIR");
}
void print_ADD_help() {
- ckhelp("Add a config for ck to keep track of.\n");
- ckhelp("The file will be stored to the desired directory and will");
- ckhelp("be linked back to it's original position.\n");
- ckhelp("It takes the following arguments:");
- ckhelp(" `program_name`: the name of the config's program");
- ckhelp(" `path`: path to the configuration (can be relative)\n");
- ckhelp("It also takes the flags:");
- ckhelp(" `-p`: to mark a configuration as primary (so it will open with edit by default)");
- ckhelp(" `-s`: to mark a configuration as secret (to end up in the secret dir)\n");
- ckhelp("Note:\nThere can be only one primary config per program.");
- ckhelp("It is advised to use your distribution's package name for the program_name.");
- ckhelp("The arguments have to be in the order shown here (name -> path -> flags)");
- report_help();
+ HELP("ck add PROGRAM_NAME CONFIG_PATH [-p] [-s]");
}
void print_DEL_help() {
- ckhelp("Delete a program/config from ck.\n");
- ckhelp("This will not interfere with any files or links, it will");
- ckhelp("just remove the program/config from the ck database.\n");
- ckhelp("To completely remove a program/config you have to manually");
- ckhelp("erase it from the folder it is stored. You can do it either before");
- ckhelp("or after running this command.\n");
- ckhelp("It takes one or two arguments:");
- ckhelp(" `program_name`: will delete all configs under that program.");
- ckhelp(" `-c path`: will delete the config specified by the path.\n");
- ckhelp("Note:\nThe path that follows the -c option has to be the path shown");
- ckhelp("when you list the configurations of a program. (ck help list for more)");
- report_help();
+ HELP("ck delete PROGRAM_NAME [CONFIG_BASENAME]");
}
void print_EDIT_help() {
- ckhelp("Edit a config tracked by ck.\n");
- ckhelp("It takes one or two arguments:");
- ckhelp(" `program_name`: will open the primary config of that program (if set)");
- ckhelp(" `config_name`: will open the specified config\n");
- ckhelp("Note:\nIf a program has only one config, edit will open it even if it's not the primary.");
- ckhelp("Edit will use the $EDITOR and if it's not set it falls back to nano.");
- ckhelp("If there is ambiguity ck will list the available config names");
- ckhelp("for the program specified.");
- report_help();
+ HELP("ck edit PROGRAM_NAME [CONFIG_BASENAME]");
}
void print_LIST_help() {
- ckhelp("List various stuff ck knows about.\n");
- ckhelp("List can work in a few different ways:");
- ckhelp(" `tree`: list all the programs and paths in a tree like structure.");
- ckhelp(" `paths`: list all the configs ck keeps track.");
- ckhelp(" `programs`: list all the programs ck keeps track.");
- ckhelp(" `-p program_name`: list only the configs of the specified program.");
- ckhelp(" `ckconf`: list the ck configuration values.\n");
- ckhelp("There are also some flags:");
- ckhelp(" `-a`: add the attributes next to the config paths (secret,primary,root)");
- ckhelp(" `-b`: print the config basenames instead of the full path");
- ckhelp(" `-t`: change the list type. (does not work with tree or ckconf)");
- ckhelp(" `plain`: default plain listing");
- ckhelp(" `python`: enclose the list in [ , ]");
- ckhelp(" `lisp`: enclose the list in ( , )");
+ ckhelp("ck list tree [-a] [-b]");
+ ckhelp("ck list -p PROGRAM_NAME [-t list-type] [-a] [-b]");
+ ckhelp("ck list programs [-t list-type] [-a] [-b]");
+ ckhelp("ck list paths [-t list-type] [-a] [-b]");
+ ckhelp("ck list ckconf");
report_help();
}
void print_SEARCH_help() {
- ckhelp("Search through the configs ck keeps track of.\n");
- ckhelp("Search performs a grep with the supplied term to each");
- ckhelp("file ck keeps track and prints the results.\n");
- ckhelp("The exact grep command used is `grep -H -n`\n");
- ckhelp("It takes one argument:");
- ckhelp(" `search_term`\n");
- ckhelp("Note:\nIf you want to search for a phrase enclose it in \'\' or \"\"");
- report_help();
+ HELP("ck search SEARCH_TERM");
}
void print_HELP_help() {
- ckhelp("Get help for ck actions.\n");
- ckhelp("It takes one argument:");
- ckhelp(" `action`\n");
- ckhelp("Note:\nRunning ck without arguments will print all the available actions.");
- report_help();
+ HELP("ck help action");
}
void print_RESTORE_help() {
- ckhelp("Restore links.\n");
- ckhelp("Given a working ck instance (ckdb + ckrc + directories in ckrc with configs)");
- ckhelp("restore shall recreate the links from the config directories in ckrc");
- ckhelp("back to their corresponding position when added in ck.\n");
- ckhelp("It is useful for copying your configs to a new linux installation");
- ckhelp("or restoring deleted links.\n");
- ckhelp("It can either restore a specific program or all of them:");
- ckhelp(" `-p progName`: restores progName.");
- ckhelp(" `all`: restores everything.\n");
- ckhelp("Note:\nIf ck tracks configs that are owned by root, simply running");
- ckhelp("`ck restore ...` will fail due to permissions. To remedy this, ck will alter the");
- ckhelp("owner and group of a link to match the one in the ckrc directories.");
- ckhelp("Thus, running `sudo ck -c /home/myuser/.ck restore ..` will restore");
- ckhelp("the root user's links as it should and the user links will have");
- ckhelp("the user as the owner instead of the root.\n");
- ckhelp("ck checks that the configs exist and that the location for the link");
- ckhelp("is avaliable before making any links. However, in the even that symlink");
- ckhelp("fails for some other reason, the process will stop as is. Make sure you");
- ckhelp("take care of the already created links, if that's the case.");
+ ckhelp("ck restore -p PROGRAM_NAME");
+ ckhelp("ck restore all");
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();
+ HELP("ck [-v|--verbose] [-c|--config DIR] action [...]");
}
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();
+ HELP("ck [-v|--verbose] [-c|--config DIR] action [...]");
}