Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.

Commit 7a7f4e3

Browse files
committed
Add echo, add whoami commands
1 parent 586f5c7 commit 7a7f4e3

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

bitlab/include/cli.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,22 @@ int cli_exit(char** args);
4141
*/
4242
int cli_history(char** args);
4343

44+
/**
45+
* Echoes the input.
46+
*
47+
* @param args Input that will be echoed.
48+
* @return The exit code.
49+
*/
50+
int cli_echo(char** args);
51+
52+
/**
53+
* Prints the user name.
54+
*
55+
* @param args The arguments passed to the function should be empty.
56+
* @return The exit code.
57+
*/
58+
int cli_whoami(char** args);
59+
4460
/**
4561
* Clears CLI window.
4662
*
@@ -49,6 +65,9 @@ int cli_history(char** args);
4965
*/
5066
int cli_clear(char** args);
5167

68+
/**
69+
* Prints CLI command help.
70+
*/
5271
void print_help();
5372

5473
/**

bitlab/src/cli.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ static cli_command cli_commands[] =
1818
{.cli_command = &cli_history, .cli_command_name = "history", .cli_command_description = "Prints command history." },
1919
{.cli_command = &cli_clear, .cli_command_name = "clear", .cli_command_description = "Clears CLI screen." },
2020
{.cli_command = &cli_help, .cli_command_name = "help", .cli_command_description = "Prints command descriptions." },
21+
{.cli_command = &cli_echo, .cli_command_name = "echo", .cli_command_description = "Echoes the input." },
22+
{.cli_command = &cli_whoami, .cli_command_name = "whoami", .cli_command_description = "Prints the user name." },
2123
}; // do not add NULLs at the end
2224

2325
int cli_exit(char** args)
@@ -69,6 +71,10 @@ int cli_help(char** args)
6971
guarded_printf(" * Detailed information about clear command:\n * clear - Clears CLI screen.\n");
7072
else if (strcmp(args[0], "help") == 0)
7173
guarded_printf(" * Detailed information about help command:\n * help - Prints command descriptions.\n");
74+
else if (strcmp(args[0], "echo") == 0)
75+
guarded_printf(" * Detailed information about echo command:\n * echo - Echoes the input.\n");
76+
else if (strcmp(args[0], "whoami") == 0)
77+
guarded_printf(" * Detailed information about whoami command:\n * whoami - Prints the user name.\n");
7278
else
7379
guarded_printf(" * Detailed information not included.\n");
7480
}
@@ -77,6 +83,27 @@ int cli_help(char** args)
7783
return 0;
7884
}
7985

86+
int cli_echo(char** args)
87+
{
88+
if (args[0] == NULL)
89+
{
90+
log_message(LOG_WARN, BITLAB_LOG, __FILE__, "No arguments provided for echo command");
91+
return 1;
92+
}
93+
for (int i = 0; args[i] != NULL; ++i)
94+
guarded_printf("%s ", args[i]);
95+
guarded_printf("\n");
96+
return 0;
97+
}
98+
99+
int cli_whoami(char** args)
100+
{
101+
if (args[0] != NULL)
102+
log_message(LOG_WARN, BITLAB_LOG, __FILE__, "Arguments provided for whoami command ignored");
103+
guarded_printf("You are %s\n", getenv("USER"));
104+
return 0;
105+
}
106+
80107
int cli_clear(char** args)
81108
{
82109
if (args[0] != NULL)

0 commit comments

Comments
 (0)