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

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