implemented short option for help

This commit is contained in:
root committed 2026-10-04 23:05:27 +02:00
1 parent fe4b863d19
commit 2065116462
3 files changed
+23

No files matched your search

+1
View File
@@ -30,6 +30,7 @@ typedef struct {
size_t depth; size_t depth;
bool no_colour; bool no_colour;
bool group_directories; bool group_directories;
bool display_help;
bool long_view; bool long_view;
bool reverse_order; bool reverse_order;
bool tree_view; bool tree_view;
+19
View File
@@ -14,6 +14,7 @@
#define KEY_CASE_SENSITIVE ( ( int )'c' ) #define KEY_CASE_SENSITIVE ( ( int )'c' )
#define KEY_DEPTH ( ( int )'d' ) #define KEY_DEPTH ( ( int )'d' )
#define KEY_GROUP_DIRECTORIES ( ( int )'g' ) #define KEY_GROUP_DIRECTORIES ( ( int )'g' )
#define KEY_HELP ( ( int )'h' )
#define KEY_LONG_VIEW ( ( int )'l' ) #define KEY_LONG_VIEW ( ( int )'l' )
#define KEY_PERMISSIONS ( ( int )'p' ) #define KEY_PERMISSIONS ( ( int )'p' )
#define KEY_REVERSE_ORDER ( ( int )'r' ) #define KEY_REVERSE_ORDER ( ( int )'r' )
@@ -83,6 +84,14 @@ static struct argp_option options[] =
.doc = "group directories at the top", .doc = "group directories at the top",
.group = 0 .group = 0
}, },
{
.name = NULL,
.key = KEY_HELP,
.arg = NULL,
.flags = 0,
.doc = "display help",
.group = 0
},
{ {
.name = "long", .name = "long",
.key = KEY_LONG_VIEW, .key = KEY_LONG_VIEW,
@@ -147,6 +156,7 @@ void initialise_args( arguments_t* arguments )
arguments->depth = MAX_TREE_DEPTH; arguments->depth = MAX_TREE_DEPTH;
arguments->no_colour = false; arguments->no_colour = false;
arguments->group_directories = false; arguments->group_directories = false;
arguments->display_help = false;
arguments->long_view = false; arguments->long_view = false;
arguments->reverse_order = false; arguments->reverse_order = false;
arguments->tree_view = false; arguments->tree_view = false;
@@ -155,6 +165,7 @@ void initialise_args( arguments_t* arguments )
arguments->path = "."; arguments->path = ".";
} }
error_t parse_args( int argc, char** argv, arguments_t* arguments ) error_t parse_args( int argc, char** argv, arguments_t* arguments )
{ {
int arg_index = 0; int arg_index = 0;
@@ -164,6 +175,11 @@ error_t parse_args( int argc, char** argv, arguments_t* arguments )
log_error( "error! arg_index = %d;", arg_index ); log_error( "error! arg_index = %d;", arg_index );
} }
if ( arguments->display_help )
{
argp_help( &parser, stdout, ARGP_HELP_STD_HELP, argv[ 0 ] );
}
return 0; return 0;
} }
@@ -200,6 +216,9 @@ static error_t arg_parser( int key, char* arg, struct argp_state* state )
case KEY_GROUP_DIRECTORIES: case KEY_GROUP_DIRECTORIES:
arguments->group_directories = true; arguments->group_directories = true;
break; break;
case KEY_HELP:
arguments->display_help = true;
break;
case KEY_LONG_VIEW: case KEY_LONG_VIEW:
arguments->long_view = true; arguments->long_view = true;
break; break;
+3
View File
@@ -62,6 +62,9 @@ int main( int argc, char** argv )
initialise_args( &args ); initialise_args( &args );
parse_args( argc, argv, &args ); parse_args( argc, argv, &args );
if ( args.display_help )
return SUCCESS;
DIR* directory = opendir( args.path ); DIR* directory = opendir( args.path );
if ( !directory ) if ( !directory )