Skip to content

Commit a33e6ed

Browse files
authored
Merge pull request #471 from CortexLM/refactor/cortex-cli-production-quality
refactor(cortex-cli): add modular CLI structure and centralized utilities
2 parents 0432f83 + 3d39a9d commit a33e6ed

File tree

12 files changed

+2977
-2883
lines changed

12 files changed

+2977
-2883
lines changed

cortex-cli/src/cli/args.rs

Lines changed: 785 additions & 0 deletions
Large diffs are not rendered by default.

cortex-cli/src/cli/handlers.rs

Lines changed: 967 additions & 0 deletions
Large diffs are not rendered by default.

cortex-cli/src/cli/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//! CLI argument parsing and command dispatch.
2+
//!
3+
//! This module provides the core CLI infrastructure:
4+
//! - Command-line argument definitions using clap
5+
//! - Version and help text formatting
6+
//! - Subcommand dispatch
7+
//!
8+
//! # Module Structure
9+
//!
10+
//! - `args` - Command-line argument structures
11+
//! - `styles` - ANSI styling for help output
12+
//! - `handlers` - Command execution handlers
13+
14+
pub mod args;
15+
pub mod handlers;
16+
pub mod styles;
17+
18+
// Re-export main types
19+
pub use args::{Cli, ColorMode, Commands, InteractiveArgs, LogLevel};
20+
pub use handlers::dispatch_command;
21+
pub use styles::{AFTER_HELP, BEFORE_HELP, get_styles};

cortex-cli/src/cli/styles.rs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
//! CLI styling and formatting.
2+
//!
3+
//! Defines ANSI colors and formatting for the CLI help output.
4+
5+
use clap::builder::styling::{AnsiColor, Effects, Styles};
6+
7+
/// Cortex CLI styled help theme.
8+
///
9+
/// Uses a modern color scheme with cyan accents for a beautiful terminal experience.
10+
pub fn get_styles() -> Styles {
11+
Styles::styled()
12+
// Headers (USAGE, COMMANDS, OPTIONS) - Bold cyan
13+
.header(AnsiColor::Cyan.on_default() | Effects::BOLD)
14+
// Usage line - Green
15+
.usage(AnsiColor::Green.on_default() | Effects::BOLD)
16+
// Literals (command names, flag names) - Bold green
17+
.literal(AnsiColor::Green.on_default() | Effects::BOLD)
18+
// Placeholders (<VALUE>, [ARGS]) - Yellow
19+
.placeholder(AnsiColor::Yellow.on_default())
20+
// Errors - Bold red
21+
.error(AnsiColor::Red.on_default() | Effects::BOLD)
22+
// Valid values - Cyan
23+
.valid(AnsiColor::Cyan.on_default())
24+
// Invalid values - Yellow
25+
.invalid(AnsiColor::Yellow.on_default())
26+
}
27+
28+
/// After-help section with environment variables documentation.
29+
pub const AFTER_HELP: &str = color_print::cstr!(
30+
r#"
31+
<cyan,bold>ENVIRONMENT VARIABLES:</>
32+
<green,bold>CORTEX_HOME</> Override config directory (default: ~/.config/cortex)
33+
<green,bold>CORTEX_API_KEY</> API key (alternative to --with-api-key)
34+
<green,bold>CORTEX_MODEL</> Default model (alternative to --model)
35+
<green,bold>CORTEX_LOG_LEVEL</> Log verbosity (error, warn, info, debug, trace)
36+
<green,bold>NO_COLOR</> Disable colored output (set to '1' or 'true')
37+
<green,bold>VISUAL</> Editor for /edit command (fallback: EDITOR)
38+
<green,bold>EDITOR</> Fallback editor if VISUAL is not set
39+
40+
<cyan,bold>PATHS:</>
41+
<green,bold>Config file</> ~/.config/cortex/config.toml
42+
<green,bold>Sessions</> ~/.local/share/cortex/sessions/
43+
<green,bold>Logs</> ~/.cache/cortex/logs/
44+
<green,bold>Agents</> ~/.cortex/agents/ (personal), .cortex/agents/ (project)
45+
46+
<cyan,bold>QUICK START:</>
47+
<yellow>cortex</> Start interactive TUI
48+
<yellow>cortex</> <dim>"fix the bug"</> Start TUI with initial prompt
49+
<yellow>cortex run</> <dim>"explain this"</> Non-interactive single request
50+
<yellow>cortex exec</> <dim>"run tests"</> Headless execution for CI/CD
51+
<yellow>cortex resume --last</> Continue most recent session
52+
53+
<cyan,bold>LEARN MORE:</>
54+
Documentation: <blue,underline>https://docs.cortex.foundation</>
55+
Report issues: <blue,underline>https://github.com/CortexLM/cortex-cli/issues</>
56+
"#
57+
);
58+
59+
/// Before-help section with ASCII art banner.
60+
pub const BEFORE_HELP: &str = color_print::cstr!(
61+
r#"
62+
<cyan,bold> ██████╗ ██████╗ ██████╗ ████████╗███████╗██╗ ██╗</>
63+
<cyan,bold> ██╔════╝██╔═══██╗██╔══██╗╚══██╔══╝██╔════╝╚██╗██╔╝</>
64+
<cyan,bold> ██║ ██║ ██║██████╔╝ ██║ █████╗ ╚███╔╝ </>
65+
<cyan,bold> ██║ ██║ ██║██╔══██╗ ██║ ██╔══╝ ██╔██╗ </>
66+
<cyan,bold> ╚██████╗╚██████╔╝██║ ██║ ██║ ███████╗██╔╝ ██╗</>
67+
<cyan,bold> ╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═╝</>
68+
<dim> AI-Powered Coding Agent</>
69+
"#
70+
);
71+
72+
/// Command category display names for styled help output.
73+
pub mod categories {
74+
pub const EXECUTION: &str = "Execution Modes";
75+
pub const SESSION: &str = "Session Management";
76+
pub const AUTH: &str = "Authentication";
77+
pub const EXTENSION: &str = "Extensibility";
78+
pub const CONFIG: &str = "Configuration";
79+
pub const UTILITIES: &str = "Utilities";
80+
pub const ADVANCED: &str = "Advanced";
81+
}

cortex-cli/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,18 @@
2323
//!
2424
//! The crate is organized into the following structure:
2525
//!
26-
//! - `utils/` - Shared utilities (validation, paths, clipboard, terminal)
26+
//! - `cli/` - CLI argument parsing and command dispatch
27+
//! - `utils/` - Shared utilities (validation, paths, clipboard, terminal, model, etc.)
2728
//! - Command modules - Individual CLI commands (`*_cmd.rs`)
2829
//! - `styled_output` - Themed terminal output formatting
2930
//! - `login` - Authentication management
3031
3132
use std::panic;
3233
use std::sync::atomic::{AtomicBool, AtomicI32, Ordering};
3334

35+
// Re-export the CLI module for command-line parsing
36+
pub mod cli;
37+
3438
// Re-export the utilities module for shared functionality
3539
pub mod utils;
3640

0 commit comments

Comments
 (0)