Skip to content

Commit eae06c7

Browse files
committed
Enhances CLI help output with color and formatting
Improves the readability and visual appeal of the CLI help message by adding color-coded elements for better clarity. This change introduces color to distinguish between different sections and options, making the help message easier to understand and navigate for users. It uses constants for colors.
1 parent e5f3a26 commit eae06c7

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

bin/regex

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -74,26 +74,35 @@ function output(string $text): void
7474

7575
function showHelp(): void
7676
{
77-
output(bold("Regex Parser CLI Tool") . "\n\n");
78-
output("Usage: regex <command> [options] <pattern>\n\n");
79-
output(bold("Commands:\n"));
80-
output(" " . info("parse") . " <pattern> [--validate] Parse and recompile a regex pattern\n");
81-
output(" " . info("analyze") . " <pattern> Analyze a regex (parse, validate, ReDoS, explain)\n");
82-
output(" " . info("highlight") . " <pattern> [--format=auto|cli|html] Highlight regex for display\n");
83-
output(" " . info("validate") . " <pattern> Validate a regex pattern\n");
84-
output(" " . info("help") . " Show this help\n\n");
85-
output(bold("Global Options:\n"));
86-
output(" --ansi Force ANSI output\n");
87-
output(" --no-ansi Disable ANSI output\n");
88-
output(" -q, --quiet Suppress output\n");
89-
output(" --silent Same as --quiet\n");
90-
output(" --help Show this help\n\n");
91-
output(bold("Examples:\n"));
92-
output(" regex parse '/a+/'\n");
93-
output(" regex analyze '/a+/'\n");
94-
output(" regex highlight '/a+/' --format=cli\n");
95-
output(" regex validate '/a+/'\n");
96-
output(" regex '/a+/' # Shortcut for highlight\n");
77+
output(color("Regex Parser", CYAN) . "\n");
78+
output(color(str_repeat("=", 12), CYAN) . "\n\n");
79+
80+
output(color("Description:", MAGENTA) . "\n");
81+
output(" " . bold("A beautiful CLI tool for regex parsing, validation, and analysis") . "\n\n");
82+
83+
output(color("Usage:", MAGENTA) . "\n");
84+
output(" regex " . color("<command>", YELLOW) . " " . color("[options]", CYAN) . " " . color("<pattern>", GREEN) . "\n\n");
85+
86+
output(color("Commands:", MAGENTA) . "\n");
87+
output(" " . info("parse") . " Parse and recompile a regex pattern\n");
88+
output(" " . info("analyze") . " Analyze a regex (parse, validate, ReDoS, explain)\n");
89+
output(" " . info("highlight") . " Highlight regex for display\n");
90+
output(" " . info("validate") . " Validate a regex pattern\n");
91+
output(" " . info("help") . " Display this help message\n\n");
92+
93+
output(color("Global Options:", MAGENTA) . "\n");
94+
output(" " . color("--ansi", CYAN) . " Force ANSI output\n");
95+
output(" " . color("--no-ansi", CYAN) . " Disable ANSI output\n");
96+
output(" " . color("-q, --quiet", CYAN) . " Suppress output\n");
97+
output(" " . color("--silent", CYAN) . " Same as --quiet\n");
98+
output(" " . color("--help", CYAN) . " Display this help message\n\n");
99+
100+
output(color("Examples:", MAGENTA) . "\n");
101+
output(" " . color("regex", BLUE) . " " . color("'/a+'", GREEN) . " # Quick highlight\n");
102+
output(" " . color("regex", BLUE) . " " . color("parse", YELLOW) . " " . color("'/a+'", GREEN) . " " . color("--validate", CYAN) . " # Parse with validation\n");
103+
output(" " . color("regex", BLUE) . " " . color("analyze", YELLOW) . " " . color("'/a+'", GREEN) . " # Full analysis\n");
104+
output(" " . color("regex", BLUE) . " " . color("highlight", YELLOW) . " " . color("'/a+'", GREEN) . " " . color("--format=html", CYAN) . " # HTML highlight\n");
105+
output(" " . color("regex", BLUE) . " " . color("validate", YELLOW) . " " . color("'/a+'", GREEN) . " # Quick validation\n");
97106
}
98107

99108
// Remove processed options from argv

0 commit comments

Comments
 (0)