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

Method run_with_verifier

atomic-cli/src/commands/org/set.rs:91–142  ·  view source on GitHub ↗

Inner runner that takes the slug-verification step as a parameter. Splitting this out lets tests inject a deterministic verifier (succeed / fail) without making a real network call, so we can assert the load-bearing invariant: **when verification fails, the config file is not modified**.

(&self, verify: F)

Source from the content-addressed store, hash-verified

89 /// assert the load-bearing invariant: **when verification fails, the
90 /// config file is not modified**.
91 fn run_with_verifier<F>(&self, verify: F) -> CliResult<()>
92 where
93 F: FnOnce(&str) -> CliResult<()>,
94 {
95 if self.slug.is_empty() {
96 return Err(CliError::InvalidArgument {
97 message: "Organization slug cannot be empty.".to_string(),
98 });
99 }
100
101 // Validate against the server first so a bad slug fails fast
102 // rather than self-locking subsequent commands. The `?` here is
103 // load-bearing: if it returns Err, config is not touched.
104 if !self.no_verify {
105 verify(&self.slug)?;
106 }
107
108 let mut config = GlobalConfig::load().map_err(|e| {
109 CliError::Internal(anyhow::anyhow!("Failed to load global config: {e}"))
110 })?;
111
112 // Write to the *active* server profile (named profile when one is
113 // active, else the legacy `[server]` block) so the new default is
114 // read back by org/workspace/project commands, which resolve the
115 // same profile.
116 let (server, profile_name) = config
117 .resolve_server_mut(None)
118 .map_err(|e| CliError::Internal(anyhow::anyhow!("{e}")))?;
119
120 let previous = server.default_org.clone();
121 server.default_org = Some(self.slug.clone());
122
123 config.save().map_err(|e| {
124 CliError::Internal(anyhow::anyhow!("Failed to save global config: {e}"))
125 })?;
126
127 match &profile_name {
128 Some(name) => print_success(&format!(
129 "Default organization for server '{name}' set to: {}",
130 self.slug
131 )),
132 None => print_success(&format!("Default organization set to: {}", self.slug)),
133 }
134
135 if let Some(prev) = &previous {
136 if prev != &self.slug {
137 print_hint(&format!("Previous default was: {prev}"));
138 }
139 }
140
141 Ok(())
142 }
143}
144
145/// Confirm the slug resolves to an org on the server.

Calls 7

print_successFunction · 0.85
print_hintFunction · 0.85
resolve_server_mutMethod · 0.80
verifyFunction · 0.50
is_emptyMethod · 0.45
cloneMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected