docs: improve CLI usage instructions and error messages
This commit is contained in:
1 file changed
+50
-29
@@ -1,33 +1,56 @@
|
|||||||
|
|
||||||
#include "app/cli.h"
|
#include "app/cli.h"
|
||||||
|
#include "config.h"
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
void print_usage(const char *program_name) {
|
void print_usage(const char *program_name) {
|
||||||
printf("KeyVibe - Mechanical Keyboard Sound Simulator\n\n");
|
printf("KeyVibe - Mechanical Keyboard Sound Simulator\n");
|
||||||
printf("Usage: %s [OPTIONS]\n\n", program_name);
|
printf("Version: %s\n\n", PROJECT_VERSION);
|
||||||
printf("Options:\n");
|
|
||||||
printf(" -S, --sound SOUND_NAME Select keyboard sound pack (default: "
|
printf("USAGE:\n");
|
||||||
"eg-oreo)\n");
|
printf(" %s [OPTIONS]\n\n", program_name);
|
||||||
|
|
||||||
|
printf("SOUND CONTROL:\n");
|
||||||
|
printf(" -S, --sound PACK Keyboard sound pack (default: eg-oreo)\n");
|
||||||
|
printf(" -M, --mouse PACK Mouse sound pack (default: ping)\n");
|
||||||
|
printf(" -l, --list List available sound packs\n\n");
|
||||||
|
|
||||||
|
printf("VOLUME CONTROL:\n");
|
||||||
printf(
|
printf(
|
||||||
" -M, --mouse SOUND_NAME Select mouse sound pack (default: ping)\n");
|
" -V, --volume LEVEL Set both keyboard & mouse volume [0-100]\n");
|
||||||
printf(" -V, --volume VOLUME Set volume [0-100] for both keyboard and "
|
printf(" -K, --keyboard-volume Set keyboard volume [0-100]\n");
|
||||||
"mouse (default: 50)\n");
|
printf(" -O, --mouse-volume Set mouse volume [0-100]\n\n");
|
||||||
printf(" -K, --keyboard-volume VOLUME Set keyboard volume [0-100] "
|
|
||||||
"(default: 50)\n");
|
printf("MUTE CONTROL:\n");
|
||||||
printf(" -O, --mouse-volume VOLUME Set mouse volume [0-100] (default: "
|
printf(" -m, --mute[=DEVICE] Mute sounds (keyboard|mouse|both)\n");
|
||||||
"50)\n");
|
printf(" -u, --unmute[=DEVICE] Unmute sounds (keyboard|mouse|both)\n\n");
|
||||||
printf(" -l, --list List available sound packs\n");
|
|
||||||
printf(" -d, --daemon Run in background (write PID file)\n");
|
printf("DAEMON CONTROL:\n");
|
||||||
printf(" -s, --stop Stop background daemon\n");
|
printf(" -d, --daemon Run in background\n");
|
||||||
printf(" -m, --mute[=DEVICE] Mute sounds (keyboard|mouse|both, "
|
printf(" -s, --stop Stop background daemon\n\n");
|
||||||
"default: both)\n");
|
|
||||||
printf(" -u, --unmute[=DEVICE] Unmute sounds (keyboard|mouse|both, "
|
printf("OTHER:\n");
|
||||||
"default: both)\n");
|
|
||||||
printf(" -h, --help Show this help message\n");
|
|
||||||
printf(" -v, --verbose Enable verbose output\n");
|
printf(" -v, --verbose Enable verbose output\n");
|
||||||
printf(" In daemon mode, editing ~/.keyvibe.json will auto-reload.\n");
|
printf(" -h, --help Show this help\n\n");
|
||||||
|
|
||||||
|
printf("EXAMPLES:\n");
|
||||||
|
printf(" %s --list # List sound packs\n",
|
||||||
|
program_name);
|
||||||
|
printf(" %s -S cherrymx-blue -V 75 # Cherry MX Blue at "
|
||||||
|
"75%%\n",
|
||||||
|
program_name);
|
||||||
|
printf(" %s --daemon # Run in background\n",
|
||||||
|
program_name);
|
||||||
|
printf(" %s --mute keyboard # Mute only keyboard\n",
|
||||||
|
program_name);
|
||||||
|
printf(" %s --keyboard-volume 80 --mouse-volume 60 # Different volumes\n",
|
||||||
|
program_name);
|
||||||
|
printf("\n");
|
||||||
|
printf("CONFIG: Settings are saved to ~/.keyvibe.json and auto-reload in "
|
||||||
|
"daemon mode.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int parse_cli(int argc, char **argv, CliOptions *out) {
|
int parse_cli(int argc, char **argv, CliOptions *out) {
|
||||||
@@ -66,7 +89,8 @@ int parse_cli(int argc, char **argv, CliOptions *out) {
|
|||||||
(n == 6 && strncmp(a, "unmute", 6) == 0) ||
|
(n == 6 && strncmp(a, "unmute", 6) == 0) ||
|
||||||
(n == 4 && strncmp(a, "help", 4) == 0) ||
|
(n == 4 && strncmp(a, "help", 4) == 0) ||
|
||||||
(n == 7 && strncmp(a, "verbose", 7) == 0))) {
|
(n == 7 && strncmp(a, "verbose", 7) == 0))) {
|
||||||
fprintf(stderr, "Unknown option: %s (use full option name)\n", argv[i]);
|
fprintf(stderr, "Error: Unknown option '%s'\n", argv[i]);
|
||||||
|
fprintf(stderr, "Use '%s --help' for available options.\n", argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -118,9 +142,8 @@ int parse_cli(int argc, char **argv, CliOptions *out) {
|
|||||||
} else if (strcmp(optarg, "mouse") == 0) {
|
} else if (strcmp(optarg, "mouse") == 0) {
|
||||||
out->mouse_mute = 1;
|
out->mouse_mute = 1;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,
|
fprintf(stderr, "Error: Invalid mute device '%s'\n", optarg);
|
||||||
"Invalid mute option: %s. Use 'keyboard', 'mouse', or 'both'\n",
|
fprintf(stderr, "Use: keyboard, mouse, or both\n");
|
||||||
optarg);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -133,10 +156,8 @@ int parse_cli(int argc, char **argv, CliOptions *out) {
|
|||||||
} else if (strcmp(optarg, "mouse") == 0) {
|
} else if (strcmp(optarg, "mouse") == 0) {
|
||||||
out->mouse_mute = 0;
|
out->mouse_mute = 0;
|
||||||
} else {
|
} else {
|
||||||
fprintf(
|
fprintf(stderr, "Error: Invalid unmute device '%s'\n", optarg);
|
||||||
stderr,
|
fprintf(stderr, "Use: keyboard, mouse, or both\n");
|
||||||
"Invalid unmute option: %s. Use 'keyboard', 'mouse', or 'both'\n",
|
|
||||||
optarg);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in new issue
Block a user