Projects acosom ziit ziit-cli Commits d66039b2
ctrl k
  • src/list.c
    ■ ■ ■ ■ ■ ■
    skipped 24 lines
    25 25   
    26 26  static void print_help()
    27 27  {
    28  - printf("Usage: ziit add [OPTION...] <interval> <message> [<tags>]\n");
    29  - printf("Adds a new entry to the time log.\n\n");
     28 + printf("Usage: ziit list [-r <repository>] <interval>\n");
     29 + printf("Lists entries in the specified interval.\n\n");
    30 30   cag_option_print(options, CAG_ARRAY_SIZE(options), stdout);
    31 31  }
    32 32   
    skipped 173 lines
  • src/main.c
    ■ ■ ■ ■ ■ ■
    skipped 5 lines
    6 6  #include "config.h"
    7 7  #include "init.h"
    8 8  #include "list.h"
     9 +#include "summary.h"
    9 10  #include "remove.h"
    10 11  #include "status.h"
    11 12  #include <cargs.h>
    skipped 50 lines
    62 63   result = run_remove(argc, argv, cfg);
    63 64   } else if (strcmp(subprogram, "list") == 0) {
    64 65   result = run_list(argc, argv, cfg);
     66 + } else if (strcmp(subprogram, "summary") == 0) {
     67 + result = run_summary(argc, argv, cfg);
    65 68   } else {
    66 69   printf("Unknown command.\n");
    67 70   }
    skipped 13 lines
  • src/message.proto
    ■ ■ ■ ■ ■ ■
    skipped 72 lines
    73 73   bytes cookie = 1;
    74 74   uint64 from = 2;
    75 75   uint64 to = 3;
    76  - uint64 interval = 4;
     76 + string time_format = 4;
     77 +}
     78 + 
     79 +message ZiitSummaryInterval {
     80 + string name = 1;
     81 + repeated ZiitSummaryEntry entries = 2;
    77 82  }
    78 83   
    79 84  message ZiitSummaryEntry {
    80  - uint64 from = 1;
    81  - uint64 to = 2;
    82  - string tag = 3;
    83  - uint64 required = 4;
    84  - uint64 tracked = 5;
     85 + string tag = 1;
     86 + uint64 duration = 2;
     87 + uint64 required = 3;
     88 + uint64 tracked = 4;
    85 89  }
    86 90   
    87 91  message ZiitSummaryResponse {
    88 92   StatusCode code = 1;
    89  - repeated ZiitSummaryEntry entries = 2;
     93 + uint64 start = 2;
     94 + uint64 offset = 3;
     95 + repeated ZiitSummaryInterval intervals = 4;
    90 96  }
    91 97   
    92 98  enum OpCode {
    skipped 32 lines
  • src/remove.c
    ■ ■ ■ ■
    skipped 24 lines
    25 25   
    26 26  static void print_help()
    27 27  {
    28  - printf("Usage: ziit rm [OPTION...] <interval>\n");
     28 + printf("Usage: ziit remove [-r <repository>] <interval>\n");
    29 29   printf("Removes all entries within the interval.\n\n");
    30 30   cag_option_print(options, CAG_ARRAY_SIZE(options), stdout);
    31 31  }
    skipped 105 lines
  • src/summary.c
    ■ ■ ■ ■ ■ ■
     1 +#include "summary.h"
     2 +#include "constants.h"
     3 +#include "interval.h"
     4 +#include "message.pb-c.h"
     5 +#include "net.h"
     6 +#include <cargs.h>
     7 +#include <confuse.h>
     8 +#include <stdio.h>
     9 +#include <stdlib.h>
     10 +#include <string.h>
     11 +#include <time.h>
     12 + 
     13 +static cag_option options[] = {
     14 + {.identifier = 'r',
     15 + .access_letters = "r",
     16 + .access_name = "repository",
     17 + .description = "Specify the repository name to operate on.",
     18 + .value_name = "NAME"},
     19 + {.identifier = 'g',
     20 + .access_letters = "g",
     21 + .access_name = "group",
     22 + .description = "Specify the sub-interval format. e.g. %m",
     23 + .value_name = "FORMAT"},
     24 + {.identifier = 'h',
     25 + .access_letters = "h",
     26 + .access_name = "help",
     27 + .description = "Shows the help for the remove command.",
     28 + .value_name = NULL},
     29 +};
     30 + 
     31 +static void print_help()
     32 +{
     33 + printf("Usage: ziit summary [-r <repository>] <interval>\n");
     34 + printf("Removes all entries within the interval.\n\n");
     35 + cag_option_print(options, CAG_ARRAY_SIZE(options), stdout);
     36 +}
     37 + 
     38 +static int pad_right(char *buffer, int buffer_len, int padding)
     39 +{
     40 + size_t content_len;
     41 + 
     42 + if (buffer_len < padding + 1) {
     43 + return -1;
     44 + }
     45 + 
     46 + buffer[padding] = '\0';
     47 + content_len = strlen(buffer);
     48 + 
     49 + for (int i = (int)content_len; i < padding; ++i) {
     50 + buffer[i] = ' ';
     51 + }
     52 + 
     53 + if (content_len > padding - 2) {
     54 + for (int i = padding - 4; i < padding - 1 && i > 3; ++i) {
     55 + buffer[i] = '.';
     56 + }
     57 + buffer[padding - 1] = ' ';
     58 + }
     59 + 
     60 + return 0;
     61 +}
     62 + 
     63 +int run_summary(int argc, char *argv[], cfg_t *cfg)
     64 +{
     65 + 
     66 + ziit_connection con;
     67 + ZiitMessage sm_message, *response;
     68 + ZiitSummaryRequest sm_request;
     69 + cag_option_context ctx;
     70 + const char *repository, *interval, *group;
     71 + int option_index, option_count;
     72 + 
     73 + ziit_message__init(&sm_message);
     74 + ziit_summary_request__init(&sm_request);
     75 + 
     76 + cag_option_prepare(&ctx, options, CAG_ARRAY_SIZE(options), argc, argv);
     77 + 
     78 + repository = "default";
     79 + group = "";
     80 + 
     81 + while (cag_option_fetch(&ctx)) {
     82 + char identifier = cag_option_get(&ctx);
     83 + switch (identifier) {
     84 + case 'r':
     85 + repository = cag_option_get_value(&ctx);
     86 + break;
     87 + case 'g':
     88 + group = cag_option_get_value(&ctx);
     89 + break;
     90 + default:
     91 + fprintf(stderr, "Unknown option supplied to the command. Aborting.\n");
     92 + case 'h':
     93 + print_help();
     94 + return EXIT_FAILURE;
     95 + }
     96 + }
     97 + 
     98 + option_index = cag_option_get_index(&ctx) + 1;
     99 + option_count = argc - option_index;
     100 + if (option_count < 1) {
     101 + fprintf(stderr, "Insufficient arguments supplied.\n");
     102 + print_help();
     103 + return EXIT_FAILURE;
     104 + }
     105 + 
     106 + interval = argv[option_index];
     107 + 
     108 + if (ziit_parse_interval(interval, &sm_request.from, &sm_request.to) < 0) {
     109 + fprintf(stderr, "Could not parse supplied interval.\n");
     110 + print_help();
     111 + return EXIT_FAILURE;
     112 + }
     113 + 
     114 + sm_request.time_format = (char *)group;
     115 + sm_request.to += sm_request.from;
     116 + 
     117 + if (ziit_connection_open(&con, cfg, repository) < 0) {
     118 + fprintf(stderr, "Could not open connection.\n");
     119 + goto err_open;
     120 + }
     121 + 
     122 + sm_message.content_case = ZIIT_MESSAGE__CONTENT_SUMMARY_REQUEST;
     123 + sm_message.summary_request = &sm_request;
     124 + 
     125 + if (ziit_connection_send(&con, &sm_message) < 0) {
     126 + fprintf(stderr, "Could not send add message to server.\n");
     127 + goto err_send;
     128 + }
     129 + 
     130 + response = ziit_connection_receive(&con);
     131 + if (response == NULL) {
     132 + fprintf(stderr, "Could not receive response from server.\n");
     133 + goto err_response;
     134 + }
     135 + 
     136 + if (response->content_case != ZIIT_MESSAGE__CONTENT_SUMMARY_RESPONSE) {
     137 + fprintf(stderr, "Unexpected answer from server.\n");
     138 + goto err_res_type;
     139 + }
     140 + 
     141 + if (response->rm_response->code != 0) {
     142 + fprintf(stderr, "%s", response->rm_response->message);
     143 + goto err_result;
     144 + } else {
     145 + char from_buffer[255], to_buffer[255];
     146 + time_t t;
     147 + struct tm *tf;
     148 + t = (time_t)sm_request.from;
     149 + tf = localtime(&t);
     150 + strftime(from_buffer, sizeof(from_buffer), "%Y-%m-%dT%H:%M:%S %Z", tf);
     151 + t = (time_t)sm_request.to;
     152 + tf = localtime(&t);
     153 + strftime(to_buffer, sizeof(to_buffer), "%Y-%m-%dT%H:%M:%S %Z", tf);
     154 + 
     155 + printf("Summary between %s and %s.\n", from_buffer, to_buffer);
     156 + ZiitSummaryEntry *entry;
     157 + ZiitSummaryInterval *sm_interval;
     158 + for (int i = 0; i < response->summary_response->n_intervals; ++i) {
     159 + 
     160 + sm_interval = response->summary_response->intervals[i];
     161 + printf("GROUP: '%s'\n", sm_interval->name);
     162 + 
     163 + snprintf(from_buffer, 255, "TAG");
     164 + pad_right(from_buffer, 255, 17);
     165 + printf("%s", from_buffer);
     166 + printf("DURATION\n");
     167 + 
     168 + for (int l = 0; l < 35; ++l) {
     169 + printf("-");
     170 + }
     171 + printf("\n");
     172 + 
     173 + for (int j = 0; j < sm_interval->n_entries; ++j) {
     174 + entry = sm_interval->entries[j];
     175 + snprintf(from_buffer, 255, "%s", entry->tag);
     176 + pad_right(from_buffer, 255, 17);
     177 + printf("%s%lih%02lim%02lis\n", from_buffer, entry->duration / 3600,
     178 + (entry->duration % 3600) / 60, entry->duration % 60);
     179 + }
     180 + 
     181 + for (int l = 0; l < 35; ++l) {
     182 + printf("_");
     183 + }
     184 + printf("\n\n");
     185 + }
     186 + }
     187 + 
     188 + ziit_message__free_unpacked(response, NULL);
     189 + ziit_connection_close(&con);
     190 + 
     191 + return EXIT_SUCCESS;
     192 + 
     193 +err_result:
     194 +err_res_type:
     195 + ziit_message__free_unpacked(response, NULL);
     196 +err_response:
     197 +err_send:
     198 + ziit_connection_close(&con);
     199 +err_open:
     200 + return -1;
     201 +}
     202 + 
  • src/summary.h
    ■ ■ ■ ■ ■ ■
     1 +#pragma once
     2 + 
     3 +#include <confuse.h>
     4 + 
     5 +int run_summary(int argc, char *argv[], cfg_t *cfg);
     6 + 
     7 + 
  • ziit.1
    ■ ■ ■ ■
    skipped 23 lines
    24 24  [-r reponame] <interval> <searchterm>
    25 25   
    26 26  .B ziit summary
    27  -[-r reponame] <interval>
     27 +[-r reponame] [-f format] <interval>
    28 28   
    29 29  .SH DESCRIPTION
    30 30  The ziit tool can be used to read and write time logs to a ziit server. In order
    skipped 63 lines
Page is in error, reload to recover