()
| 933 | } |
| 934 | |
| 935 | fn main() { |
| 936 | // Initialize logging |
| 937 | init_logging(); |
| 938 | |
| 939 | // Dynamic shell completion. When invoked in completion mode (the `COMPLETE` |
| 940 | // env var is set by the installed shell hook), this emits candidates — |
| 941 | // including live view names and change hashes registered on the insert |
| 942 | // args — and exits before normal argument parsing. In normal invocations |
| 943 | // it is a no-op. The factory mirrors the real command tree so completion |
| 944 | // matches actual subcommands and aliases. |
| 945 | clap_complete::CompleteEnv::with_factory(|| apply_agent_help(Cli::command())).complete(); |
| 946 | |
| 947 | // Parse command-line arguments through the agent-native help layout. |
| 948 | // |
| 949 | // `try_get_matches_from_mut` rather than `get_matches`: clap's own failure |
| 950 | // output is human prose ending in "For more information, try '--help'", |
| 951 | // which costs an agent a second round trip and may discard the option/value |
| 952 | // relationship or the parser's underlying cause. We intercept and re-render |
| 953 | // in the same `key: value` dialect the rest of the machine surface speaks. |
| 954 | // Help and version still print through clap untouched. |
| 955 | let mut cmd = apply_agent_help(Cli::command()); |
| 956 | let args: Vec<std::ffi::OsString> = std::env::args_os().collect(); |
| 957 | let matches = match cmd.try_get_matches_from_mut(args.clone()) { |
| 958 | Ok(matches) => matches, |
| 959 | Err(err) => agent_error::render_and_exit(err, &cmd, &args), |
| 960 | }; |
| 961 | let cli = match Cli::from_arg_matches(&matches) { |
| 962 | Ok(cli) => cli, |
| 963 | Err(err) => agent_error::render_and_exit(err, &cmd, &args), |
| 964 | }; |
| 965 | |
| 966 | // Configure color output |
| 967 | if cli.no_color { |
| 968 | // Disable colors globally |
| 969 | console::set_colors_enabled(false); |
| 970 | console::set_colors_enabled_stderr(false); |
| 971 | } |
| 972 | |
| 973 | // Execute the command and handle errors |
| 974 | let result = match cli.command { |
| 975 | Commands::Agent(agent) => agent.run(), |
| 976 | |
| 977 | Commands::Init(init) => init.run(), |
| 978 | |
| 979 | Commands::Status(status) => status.run(), |
| 980 | |
| 981 | Commands::Conflicts(conflicts) => conflicts.run(), |
| 982 | |
| 983 | Commands::Add(add) => add.run(), |
| 984 | |
| 985 | Commands::Remove(remove) => remove.run(), |
| 986 | |
| 987 | Commands::Move(mv) => mv.run(), |
| 988 | |
| 989 | Commands::Restore(restore) => restore.run(), |
| 990 | |
| 991 | Commands::Sandbox(sandbox) => sandbox.run(), |
| 992 |
nothing calls this directly
no test coverage detected