()
| 955 | // Main Entry Point |
| 956 | |
| 957 | fn main() { |
| 958 | // Unix CLI convention: a closed downstream pipe is a silent exit, not a |
| 959 | // Rust panic. Shells routinely run `atomic … | head`/`awk` pipelines that |
| 960 | // close the pipe after the first lines; without the default disposition |
| 961 | // `println!` panics on the broken pipe and the pipeline dies with exit |
| 962 | // 101 instead of the consumer's status. |
| 963 | #[cfg(unix)] |
| 964 | unsafe { |
| 965 | libc::signal(libc::SIGPIPE, libc::SIG_DFL); |
| 966 | } |
| 967 | |
| 968 | // Initialize logging |
| 969 | logging::init(); |
| 970 | |
| 971 | // Dynamic shell completion. When invoked in completion mode (the `COMPLETE` |
| 972 | // env var is set by the installed shell hook), this emits candidates — |
| 973 | // including live view names and change hashes registered on the insert |
| 974 | // args — and exits before normal argument parsing. In normal invocations |
| 975 | // it is a no-op. The factory mirrors the real command tree so completion |
| 976 | // matches actual subcommands and aliases. |
| 977 | clap_complete::CompleteEnv::with_factory(|| apply_agent_help(Cli::command())).complete(); |
| 978 | |
| 979 | // Parse command-line arguments through the agent-native help layout. |
| 980 | // |
| 981 | // `try_get_matches_from_mut` rather than `get_matches`: clap's own failure |
| 982 | // output is human prose ending in "For more information, try '--help'", |
| 983 | // which costs an agent a second round trip and may discard the option/value |
| 984 | // relationship or the parser's underlying cause. We intercept and re-render |
| 985 | // in the same `key: value` dialect the rest of the machine surface speaks. |
| 986 | // Help and version still print through clap untouched. |
| 987 | let mut cmd = apply_agent_help(Cli::command()); |
| 988 | let args: Vec<std::ffi::OsString> = std::env::args_os().collect(); |
| 989 | let matches = match cmd.try_get_matches_from_mut(args.clone()) { |
| 990 | Ok(matches) => matches, |
| 991 | Err(err) => agent_error::render_and_exit(err, &cmd, &args), |
| 992 | }; |
| 993 | let cli = match Cli::from_arg_matches(&matches) { |
| 994 | Ok(cli) => cli, |
| 995 | Err(err) => agent_error::render_and_exit(err, &cmd, &args), |
| 996 | }; |
| 997 | |
| 998 | let command_log = logging::CommandLog::start(&matches); |
| 999 | |
| 1000 | // Configure color output |
| 1001 | if cli.no_color { |
| 1002 | // Disable colors globally |
| 1003 | console::set_colors_enabled(false); |
| 1004 | console::set_colors_enabled_stderr(false); |
| 1005 | } |
| 1006 | |
| 1007 | // A remote sandbox's cache reaches its serving repository through this |
| 1008 | // link; and in a remote sandbox only the commands that work off its |
| 1009 | // cache run — nothing may open a repository the sandbox does not have. |
| 1010 | remote_sandbox::install_link(); |
| 1011 | if let Some((root, pointer)) = remote_sandbox::current() { |
| 1012 | let name = matches.subcommand_name().unwrap_or_default(); |
| 1013 | if !remote_sandbox::command_allowed(name) { |
| 1014 | let err = remote_sandbox::refusal( |
nothing calls this directly
no test coverage detected