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