improve cli application help
This commit is contained in:
parent
ff6b89b495
commit
a84f1e0ebe
30
main.c
30
main.c
|
@ -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");
|
||||
|
|
Loading…
Reference in a new issue