| skipped 1 lines |
2 | 2 | | #include <strings.h> |
3 | 3 | | |
4 | 4 | | #include "add.h" |
5 | | - | #include "constants.h" |
6 | 5 | | #include "config.h" |
| 6 | + | #include "constants.h" |
7 | 7 | | #include "init.h" |
8 | 8 | | #include "list.h" |
9 | | - | #include "summary.h" |
10 | 9 | | #include "remove.h" |
11 | 10 | | #include "status.h" |
| 11 | + | #include "summary.h" |
12 | 12 | | #include <cargs.h> |
13 | 13 | | #include <confuse.h> |
14 | 14 | | #include <stdlib.h> |
15 | 15 | | #include <string.h> |
16 | 16 | | #include <syslog.h> |
17 | 17 | | |
| 18 | + | static cag_option options[] = { |
| 19 | + | {.identifier = 'v', |
| 20 | + | .access_letters = "v", |
| 21 | + | .access_name = "version", |
| 22 | + | .description = "Outputs the version of the ziit client.", |
| 23 | + | .value_name = NULL}, |
| 24 | + | {.identifier = 'h', |
| 25 | + | .access_letters = "h", |
| 26 | + | .access_name = "help", |
| 27 | + | .description = "Shows the help for the add command.", |
| 28 | + | .value_name = NULL}, |
| 29 | + | }; |
| 30 | + | |
18 | 31 | | cfg_opt_t repository_opts[] = {CFG_STR("addr", ZIIT_DEFAULT_ADDR, CFGF_NONE), |
19 | 32 | | CFG_INT("port", ZIIT_DEFAULT_PORT, CFGF_NONE), |
20 | 33 | | CFG_STR("server_public_key", NULL, CFGF_NONE), |
| skipped 4 lines |
25 | 38 | | CFGF_MULTI | CFGF_TITLE), |
26 | 39 | | CFG_FUNC("include", &cfg_include), CFG_END()}; |
27 | 40 | | |
| 41 | + | static void print_help() |
| 42 | + | { |
| 43 | + | printf("Usage: ziit [OPTION...] <command>\n"); |
| 44 | + | printf("Communicates with the ziit time tracking server.\n\n"); |
| 45 | + | printf("Available commands:\n\n"); |
| 46 | + | printf(" init: Initializes the repository configuration.\n"); |
| 47 | + | printf(" status: Shows status information from the server.\n"); |
| 48 | + | printf(" add: Adds a new entry to the time log.\n"); |
| 49 | + | printf(" remove: Removes all entries within the interval.\n"); |
| 50 | + | printf(" list: Lists entries in the specified interval.\n"); |
| 51 | + | printf( |
| 52 | + | " summary: Creates a summary over all entries within the interval.\n"); |
| 53 | + | } |
| 54 | + | |
| 55 | + | static void print_version() |
| 56 | + | { |
| 57 | + | printf("ziit version v" ZIIT_VERSION "\n"); |
| 58 | + | } |
| 59 | + | |
28 | 60 | | int main(int argc, char *argv[]) |
29 | 61 | | { |
30 | 62 | | int result; |
| 63 | + | cag_option_context ctx; |
| 64 | + | char identifier; |
31 | 65 | | const char *subprogram; |
32 | 66 | | char config_path[FILENAME_MAX]; |
33 | 67 | | cfg_t *cfg; |
| 68 | + | |
| 69 | + | if (argc == 2) { |
| 70 | + | cag_option_prepare(&ctx, options, CAG_ARRAY_SIZE(options), argc, argv); |
| 71 | + | while (cag_option_fetch(&ctx)) { |
| 72 | + | identifier = cag_option_get(&ctx); |
| 73 | + | switch (identifier) { |
| 74 | + | case 'v': |
| 75 | + | print_version(); |
| 76 | + | return EXIT_SUCCESS; |
| 77 | + | case 'h': |
| 78 | + | print_help(); |
| 79 | + | return EXIT_SUCCESS; |
| 80 | + | } |
| 81 | + | } |
| 82 | + | } |
34 | 83 | | |
35 | 84 | | cfg = cfg_init(opts, CFGF_NOCASE); |
36 | 85 | | |
| skipped 29 lines |
66 | 115 | | } else if (strcmp(subprogram, "summary") == 0) { |
67 | 116 | | result = run_summary(argc, argv, cfg); |
68 | 117 | | } else { |
69 | | - | printf("Unknown command.\n"); |
| 118 | + | print_help(); |
| 119 | + | return EXIT_FAILURE; |
70 | 120 | | } |
71 | 121 | | } else { |
72 | | - | printf("ziit init, ziit add... \n"); |
| 122 | + | print_help(); |
| 123 | + | return EXIT_SUCCESS; |
73 | 124 | | } |
74 | 125 | | cfg_free(cfg); |
75 | 126 | | |
| skipped 8 lines |