diff options
| -rw-r--r-- | src/main.c | 31 |
1 files changed, 25 insertions, 6 deletions
@@ -336,9 +336,14 @@ static int table_next_id(sqlite3 *db, const char *table) return last_id + 1; } -static void ftag_export_help(void) +static void ftag_export_usage(void) { puts("Usage: ftag export [OPTION]... ARCHIVE"); +} + +static void ftag_export_help(void) +{ + ftag_export_usage(); puts("Export files from the database to an archive. Files are read from"); puts("standard input, one per line. Files have to be canonical names that"); puts("exist in the database."); @@ -347,9 +352,9 @@ static void ftag_export_help(void) A file name starting with a slash can be considered as a file to take from the filesystem, not from the database. */ puts("Available options:"); + puts(" -f TODO: use files' full names"); puts(" -h print this help"); puts(" -n TODO: add user name as a suffix"); - puts(" -f TODO: use files' full names"); } /* Structure used to pass data from ftag_file_get_extension to its callback @@ -425,6 +430,19 @@ static void ftag_file_get_path(char *out, int size, const char *file) static void ftag_export(int argc, char **argv) { + while ((argc > 0) && (argv[0][0] == '-')) { + switch (argv[0][1]) { + case 'h': + ftag_export_help(); + exit(EXIT_SUCCESS); + default: + ftag_export_usage(); + exit(EXIT_FAILURE); + } + argv++; + argc--; + } + if (argc != 1) { ftag_export_help(); exit(EXIT_FAILURE); @@ -727,10 +745,6 @@ static int get_sums_callback(void *_known_sums, int, char **cols, char **) static void ftag_file_add(int argc, char **argv) { /* step 0: parse options */ - if (argc == 0) { - ftag_file_add_usage(); - exit(EXIT_FAILURE); - } int interactive = 0; int eliminate_duplicates = 1; int encrypt = 1; @@ -756,6 +770,11 @@ static void ftag_file_add(int argc, char **argv) argc--; } + if (argc == 0) { + ftag_file_add_usage(); + exit(EXIT_FAILURE); + } + /* step 1: compute file sums */ uint32_t *sums = malloc(argc*sizeof(*sums)); |
