aboutsummaryrefslogtreecommitdiffstats
path: root/src/help.c
blob: 4d32b106ef7f15e2689ad35c792b7226088bb351 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* help.c - the help action --------------------------------------------*- C -*-
 *
 * This file is part of ck, the config keeper
 *
 * -----------------------------------------------------------------------------
 *
 * Copyright (C) 2019  Anastasis Grammenos
 * GPLv3 (see LICENCE for the full notice)
 *
 * -------------------------------------------------------------------------- */
#include "dblayer.h"
#include "ckerrlog.h"

ERRLOG(action);

static void print_conf_help(void) {
  HELP("ck [-v|--verbose] [-c|--config DIR] action [...]");
}

static void print_verbose_help(void) {
  HELP("ck [-v|--verbose] [-c|--config DIR] action [...]");
}

int run_HELP(UserOpt *opt, Conf *conf) {
  UNUSED(conf);
  char tmp[STR_M] = "";
  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, MIN, MAX)                                                       \
    case CKA_##ACTION:                                                  \
      HELP("%s", get_possible_action_strings(tmp, CKA_##ACTION));       \
      print_##ACTION##_help();                                          \
      return 0;
    CK_ACTIONS
#undef X
  default:
    ERR("Unknown action: %s", list_get(opt->args));
  }
  return -1;
}

void print_HELP_help() {
  HELP("ck help action");
}