Skip to content
Snippets Groups Projects
Commit a84f1e0e authored by Carl Philipp Klemm's avatar Carl Philipp Klemm
Browse files

improve cli application help

parent ff6b89b4
No related branches found
No related tags found
No related merge requests found
......@@ -70,12 +70,28 @@ static channel_t char_to_channel(char ch)
}
}
void print_commands(void)
{
puts("Valid commands:");
puts("connect [CHANNEL]\t | connect a channels");
puts("disconnect [CHANNEL]\t | disconnect a channels");
puts("clear\t\t\t | disconnect all channels");
puts("connect_all\t\t | connect all channels");
puts("get\t\t\t | get the state of all channels");
puts("read [ADDRESS] [LENGTH]\t | read from the device eeprom at address");
puts("write [ADDRESS] [LENGTH] | write to the device eeprom at address");
}
static int process_commands(char** commands, size_t command_count, struct eismultiplexer* multiplexer, char* name)
{
if(strcmp(commands[0], "clear") == 0)
{
eismultiplexer_disconnect_channel(multiplexer, CHANNEL_NONE);
}
else if(strcmp(commands[0], "help") == 0)
{
print_commands();
}
else if(strcmp(commands[0], "write") == 0)
{
if(command_count < 3)
......@@ -147,7 +163,7 @@ static int process_commands(char** commands, size_t command_count, struct eismul
{
if(command_count != 2)
{
printf("Usage %s %s [CHANNEL]\n", name, commands[0]);
puts("A channel is required");
return 2;
}
......@@ -174,6 +190,12 @@ static int process_commands(char** commands, size_t command_count, struct eismul
return 3;
}
}
else
{
printf("%s is not a valid command\n", commands[0]);
print_commands();
return 3;
}
}
return 0;
}
......@@ -215,6 +237,12 @@ int main(int argc, char* argv[])
struct config config = {};
argp_parse(&argp, argc, argv, 0, 0, &config);
if(config.list_commands)
{
print_commands();
return 0;
}
if(config.command_count < 1 && !(config.interactive || config.pipe))
{
printf("A command is required\n");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment