diff --git a/readme.md b/readme.md index 5f17c5f..0f620bf 100644 --- a/readme.md +++ b/readme.md @@ -2,3 +2,24 @@ This is a replacement for `ls` with additional features. Though it may result as a rewrite of `eza` (formerly `exa`). + +# notes + +```c +static struct argp_option options[] = { + {"verbose", 'v', 0, 0, "Enable verbose output"}, + {"output", 'o', "FILE", 0, "Output file"}, + {0} +}; + +static void print_options(const struct argp_option *opts) +{ + for (const struct argp_option *o = opts; + o->name || o->key || o->arg || o->flags || o->doc; + ++o) + { + if (o->name) + puts(o->name); + } +} +``` diff --git a/src/arguments.c b/src/arguments.c index 4a143da..4f36dcc 100644 --- a/src/arguments.c +++ b/src/arguments.c @@ -22,9 +22,11 @@ #define KEY_TREE_VIEW ( ( int )'t' ) #define KEY_TIME_MODE ( ( int )'T' ) #define KEY_NO_COLOUR ( ( int )0x101 ) +#define KEY_COMPLETIONS ( ( int )0x102 ) // function prototypes static error_t arg_parser( int key, char* arg, struct argp_state* state ); +void print_completions( void ); // constant definitions const char* argp_program_version = "scan version 0.1"; @@ -86,7 +88,7 @@ static struct argp_option options[] = .group = 0 }, { - .name = NULL, + .name = "help", .key = KEY_HELP, .arg = NULL, .flags = 0, @@ -141,6 +143,14 @@ static struct argp_option options[] = .doc = "time to display for directory entries", .group = 0 }, + { + .name = "completions", + .key = KEY_COMPLETIONS, + .arg = NULL, + .flags = OPTION_HIDDEN, + .doc = NULL, + .group = 0 + }, { 0 } // this is required to properly end the options array .. }; @@ -309,6 +319,9 @@ static error_t arg_parser( int key, char* arg, struct argp_state* state ) return ARGP_ERR_UNKNOWN; } break; + case KEY_COMPLETIONS: + print_completions(); + break; case ARGP_KEY_ARG: if ( 0 == state->arg_num ) arguments->path_count = 0u; @@ -322,3 +335,17 @@ static error_t arg_parser( int key, char* arg, struct argp_state* state ) return 0; } + +void print_completions( void ) +{ + const struct argp_option* opt = options; + for ( opt = options; opt->name; opt++ ) + { + if ( opt->name && !(opt->flags & OPTION_HIDDEN ) ) + fprintf( stdout, "--%s\n", opt->name ); + + if ( 128 > opt->key && !(opt->flags & OPTION_HIDDEN ) ) + fprintf( stdout, "-%c\n", opt->key ); + } + exit( 0 ); +}