MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / main

Function main

atomic-cli/src/main.rs:953–1139  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 15

apply_agent_helpFunction · 0.85
render_and_exitFunction · 0.85
install_linkFunction · 0.85
command_allowedFunction · 0.85
print_errorFunction · 0.85
completeMethod · 0.80
as_refMethod · 0.80
currentFunction · 0.70
refusalFunction · 0.70
initFunction · 0.50
commandFunction · 0.50
collectMethod · 0.45

Tested by

no test coverage detected