feature to print all arguments for completions
This commit is contained in:
1 parent
079ccd4ed3
commit
6f28e63e3a
2 files changed
+49
-1
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
```
|
||||
+28
-1
@@ -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 );
|
||||
}
|
||||
Reference in new issue
Block a user