diff --git a/main.c b/main.c index 7ebe73fd7da2818c370f20014a4a251d477a527b..2544d3841f4c69a2629cd29e0c7c914d24ee100f 100644 --- a/main.c +++ b/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");