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

Method run

atomic-cli/src/commands/agent/enable.rs:155–394  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

153
154impl Command for Enable {
155 fn run(&self) -> CliResult<()> {
156 // Data-driven install — definitions come from the integration's manifest.
157 if let Some(ref manifest) = self.hooks {
158 return self.run_manifest(manifest);
159 }
160
161 // Global install — writes to ~/.claude/settings.json
162 if self.global {
163 return self.run_global();
164 }
165
166 // Find the repository root
167 let repo_root = find_repository_root()?;
168
169 // Ensure .atomic/sessions directory exists
170 let sessions_dir = repo_root.join(".atomic").join("sessions");
171 if !sessions_dir.exists() {
172 std::fs::create_dir_all(&sessions_dir).map_err(|e| {
173 crate::error::CliError::Io(std::io::Error::new(
174 e.kind(),
175 format!("Failed to create sessions directory: {}", e),
176 ))
177 })?;
178 }
179
180 let registry = AgentRegistry::with_defaults();
181
182 // Determine which agents to install for
183 let agents_to_install: Vec<&str> = if self.all {
184 // Install for all detected agents
185 let detected = registry.detect(&repo_root);
186 if detected.is_empty() {
187 // Do not install hooks when no agent is detected.
188 print_error(
189 "No agents detected in this repository — nothing to enable with --all.",
190 );
191 print_warning(
192 "Create a .claude/, .gemini/, or .agents/ directory first, or use --agent <name>.",
193 );
194 return Err(crate::error::CliError::InvalidArgument {
195 message: "no agents detected for --all".to_string(),
196 });
197 }
198 detected
199 } else if let Some(ref name) = self.agent {
200 // Specific agent requested — validate it exists
201 registry
202 .require(name)
203 .map_err(|e| crate::error::CliError::InvalidArgument {
204 message: format!("Unknown agent '{}': {}", name, e),
205 })?;
206 vec![name.as_str()]
207 } else {
208 // Auto-detect
209 let detected = registry.detect(&repo_root);
210 if detected.is_empty() {
211 // No agent detected — try to install for all, with a hint
212 let available = registry.list();

Callers 1

sync_integration_packageFunction · 0.45

Calls 15

find_repository_rootFunction · 0.85
print_errorFunction · 0.85
print_warningFunction · 0.85
resolveFunction · 0.85
print_successFunction · 0.85
install_integrationMethod · 0.80
getMethod · 0.65
run_manifestMethod · 0.45
run_globalMethod · 0.45
existsMethod · 0.45
kindMethod · 0.45

Tested by

no test coverage detected