feat(cli): add option -i to view database info
This commit is contained in:
parent
7961554b69
commit
dc5abcf9d9
@ -53,6 +53,7 @@ Options:
|
||||
-h Print this help and exit
|
||||
-I <dir> Initialize new Tanabata database in directory <dir>
|
||||
-O <dir> Open existing Tanabata database from directory <dir>
|
||||
-i View database info
|
||||
-a View all
|
||||
-s Set or add
|
||||
-u Unset or remove
|
||||
@ -71,6 +72,8 @@ Using the `-I <dir>` option, you can initialize the TFM database in the specifie
|
||||
|
||||
Using the `-O <dir>` option, you can open the TFM database in the specified directory. The app checks if the directory contains the sasahyou, sappyou and shoppyou files, and if they exist and are valid, saves the directory path to a configuration file. The new database will be used the next time you run the app until you change it.
|
||||
|
||||
Using the `-i` option, you can get info about your database. When your hyous were created and last modified, how many records and holes they have, and so on.
|
||||
|
||||
Using the `-a` option, you get the full list of what you specify. For example, `-af` prints the full list of sasa.
|
||||
|
||||
Using the `-s` option, you can add new sasa, tanzaku, or kazari. For example, `-st` launches a menu for adding new tanzaku. Just enter its name and description.
|
||||
|
||||
42
cli/cli.c
42
cli/cli.c
@ -275,9 +275,10 @@ int main(int argc, char **argv) {
|
||||
fprintf(stderr, ERROR("No options provided\n"));
|
||||
return 1;
|
||||
}
|
||||
const char *shortopts = "hI:O:suaftkwV";
|
||||
const char *shortopts = "hI:O:isuaftkwV";
|
||||
char *abspath = NULL;
|
||||
int opt;
|
||||
_Bool opt_i = 0;
|
||||
_Bool opt_a = 0;
|
||||
_Bool opt_s = 0;
|
||||
_Bool opt_u = 0;
|
||||
@ -328,6 +329,7 @@ int main(int argc, char **argv) {
|
||||
HIGHLIGHT("-h")" Print this help and exit\n"
|
||||
HIGHLIGHT("-I <dir>")" Initialize new Tanabata database in directory <dir>\n"
|
||||
HIGHLIGHT("-O <dir>")" Open existing Tanabata database from directory <dir>\n"
|
||||
HIGHLIGHT("-i")" View database info\n"
|
||||
HIGHLIGHT("-a")" View all\n"
|
||||
HIGHLIGHT("-s")" Set or add\n"
|
||||
HIGHLIGHT("-u")" Unset or remove\n"
|
||||
@ -387,6 +389,9 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
fprintf(stderr, ERROR("Failed to open Tanabata database\n"));
|
||||
return 1;
|
||||
case 'i':
|
||||
opt_i = 1;
|
||||
break;
|
||||
case 'a':
|
||||
opt_a = 1;
|
||||
break;
|
||||
@ -426,8 +431,41 @@ int main(int argc, char **argv) {
|
||||
opt_s = 0;
|
||||
opt_u = 0;
|
||||
}
|
||||
free(tanabata_path);
|
||||
fclose(config);
|
||||
if (opt_i) {
|
||||
char datetime[20];
|
||||
printf(HIGHLIGHT("Current database location: %s\n\n")
|
||||
HIGHLIGHT("SASAHYOU\n"), tanabata_path);
|
||||
strftime(datetime, 20, DT_FORMAT,
|
||||
localtime((const time_t *) &tanabata.sasahyou.created_ts));
|
||||
printf(" "HIGHLIGHT("Created")" %s\n", datetime);
|
||||
strftime(datetime, 20, DT_FORMAT,
|
||||
localtime((const time_t *) &tanabata.sasahyou.modified_ts));
|
||||
printf(" "HIGHLIGHT("Last modified")" %s\n"
|
||||
" "HIGHLIGHT("Number of sasa")" %lu\n"
|
||||
" "HIGHLIGHT("Number of holes")" %lu\n\n"
|
||||
HIGHLIGHT("SAPPYOU\n"), datetime, tanabata.sasahyou.size, tanabata.sasahyou.hole_cnt);
|
||||
strftime(datetime, 20, DT_FORMAT,
|
||||
localtime((const time_t *) &tanabata.sappyou.created_ts));
|
||||
printf(" "HIGHLIGHT("Created")" %s\n", datetime);
|
||||
strftime(datetime, 20, DT_FORMAT,
|
||||
localtime((const time_t *) &tanabata.sappyou.modified_ts));
|
||||
printf(" "HIGHLIGHT("Last modified")" %s\n"
|
||||
" "HIGHLIGHT("Number of tanzaku")" %lu\n"
|
||||
" "HIGHLIGHT("Number of holes")" %lu\n\n"
|
||||
HIGHLIGHT("SHOPPYOU\n"), datetime, tanabata.sappyou.size, tanabata.sappyou.hole_cnt);
|
||||
strftime(datetime, 20, DT_FORMAT,
|
||||
localtime((const time_t *) &tanabata.shoppyou.created_ts));
|
||||
printf(" "HIGHLIGHT("Created")" %s\n", datetime);
|
||||
strftime(datetime, 20, DT_FORMAT,
|
||||
localtime((const time_t *) &tanabata.shoppyou.modified_ts));
|
||||
printf(" "HIGHLIGHT("Last modified")" %s\n"
|
||||
" "HIGHLIGHT("Number of kazari")" %lu\n"
|
||||
" "HIGHLIGHT("Number of holes")" %lu\n",
|
||||
datetime, tanabata.shoppyou.size, tanabata.shoppyou.hole_cnt);
|
||||
return 0;
|
||||
}
|
||||
free(tanabata_path);
|
||||
if (opt_w) {
|
||||
if (tanabata_weed(&tanabata) == 0 &&
|
||||
tanabata_save(&tanabata) == 0) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user