diff --git a/cli/src/main.rs b/cli/src/main.rs index 1f86fe3c7..2ea8044f5 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -21,7 +21,7 @@ use commands::{gen_id, parse_command, ParseError}; use connection::{ensure_daemon, send_command}; use flags::{clean_args, parse_flags}; use install::run_install; -use output::{print_help, print_response}; +use output::{print_command_help, print_help, print_response}; fn run_session(args: &[String], session: &str, json_mode: bool) { let subcommand = args.get(1).map(|s| s.as_str()); @@ -98,7 +98,19 @@ fn main() { let flags = parse_flags(&args); let clean = clean_args(&args); - if clean.is_empty() || args.iter().any(|a| a == "--help" || a == "-h") { + let has_help = args.iter().any(|a| a == "--help" || a == "-h"); + + if clean.is_empty() { + print_help(); + return; + } + + if has_help { + if let Some(cmd) = clean.get(0) { + if print_command_help(cmd) { + return; + } + } print_help(); return; } diff --git a/cli/src/output.rs b/cli/src/output.rs index 9a4a775cb..4f4dadc43 100644 --- a/cli/src/output.rs +++ b/cli/src/output.rs @@ -145,6 +145,961 @@ pub fn print_response(resp: &Response, json_mode: bool) { } } +/// Print command-specific help. Returns true if help was printed, false if command unknown. +pub fn print_command_help(command: &str) -> bool { + let help = match command { + // === Navigation === + "open" | "goto" | "navigate" => r##" +agent-browser open - Navigate to a URL + +Usage: agent-browser open + +Navigates the browser to the specified URL. If no protocol is provided, +https:// is automatically prepended. + +Aliases: goto, navigate + +Global Options: + --json Output as JSON + --session Use specific session + --headed Show browser window + +Examples: + agent-browser open example.com + agent-browser open https://github.com + agent-browser open localhost:3000 +"##, + "back" => r##" +agent-browser back - Navigate back in history + +Usage: agent-browser back + +Goes back one page in the browser history, equivalent to clicking +the browser's back button. + +Global Options: + --json Output as JSON + --session Use specific session + +Examples: + agent-browser back +"##, + "forward" => r##" +agent-browser forward - Navigate forward in history + +Usage: agent-browser forward + +Goes forward one page in the browser history, equivalent to clicking +the browser's forward button. + +Global Options: + --json Output as JSON + --session Use specific session + +Examples: + agent-browser forward +"##, + "reload" => r##" +agent-browser reload - Reload the current page + +Usage: agent-browser reload + +Reloads the current page, equivalent to pressing F5 or clicking +the browser's reload button. + +Global Options: + --json Output as JSON + --session Use specific session + +Examples: + agent-browser reload +"##, + + // === Core Actions === + "click" => r##" +agent-browser click - Click an element + +Usage: agent-browser click + +Clicks on the specified element. The selector can be a CSS selector, +XPath, or an element reference from snapshot (e.g., @e1). + +Global Options: + --json Output as JSON + --session Use specific session + +Examples: + agent-browser click "#submit-button" + agent-browser click @e1 + agent-browser click "button.primary" + agent-browser click "//button[@type='submit']" +"##, + "dblclick" => r##" +agent-browser dblclick - Double-click an element + +Usage: agent-browser dblclick + +Double-clicks on the specified element. Useful for text selection +or triggering double-click handlers. + +Global Options: + --json Output as JSON + --session Use specific session + +Examples: + agent-browser dblclick "#editable-text" + agent-browser dblclick @e5 +"##, + "fill" => r##" +agent-browser fill - Clear and fill an input field + +Usage: agent-browser fill + +Clears the input field and fills it with the specified text. +This replaces any existing content in the field. + +Global Options: + --json Output as JSON + --session Use specific session + +Examples: + agent-browser fill "#email" "user@example.com" + agent-browser fill @e3 "Hello World" + agent-browser fill "input[name='search']" "query" +"##, + "type" => r##" +agent-browser type - Type text into an element + +Usage: agent-browser type + +Types text into the specified element character by character. +Unlike fill, this does not clear existing content first. + +Global Options: + --json Output as JSON + --session Use specific session + +Examples: + agent-browser type "#search" "hello" + agent-browser type @e2 "additional text" +"##, + "hover" => r##" +agent-browser hover - Hover over an element + +Usage: agent-browser hover + +Moves the mouse to hover over the specified element. Useful for +triggering hover states or dropdown menus. + +Global Options: + --json Output as JSON + --session Use specific session + +Examples: + agent-browser hover "#dropdown-trigger" + agent-browser hover @e4 +"##, + "focus" => r##" +agent-browser focus - Focus an element + +Usage: agent-browser focus + +Sets keyboard focus to the specified element. + +Global Options: + --json Output as JSON + --session Use specific session + +Examples: + agent-browser focus "#input-field" + agent-browser focus @e2 +"##, + "check" => r##" +agent-browser check - Check a checkbox + +Usage: agent-browser check + +Checks a checkbox element. If already checked, no action is taken. + +Global Options: + --json Output as JSON + --session Use specific session + +Examples: + agent-browser check "#terms-checkbox" + agent-browser check @e7 +"##, + "uncheck" => r##" +agent-browser uncheck - Uncheck a checkbox + +Usage: agent-browser uncheck + +Unchecks a checkbox element. If already unchecked, no action is taken. + +Global Options: + --json Output as JSON + --session Use specific session + +Examples: + agent-browser uncheck "#newsletter-opt-in" + agent-browser uncheck @e8 +"##, + "select" => r##" +agent-browser select - Select a dropdown option + +Usage: agent-browser select + +Selects an option in a