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

Method run

atomic-cli/src/commands/identity/new.rs:118–215  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

116
117impl Command for New {
118 fn run(&self) -> CliResult<()> {
119 // Open or create the identity store
120 let mut store = IdentityStore::open_default().map_err(|e| {
121 CliError::Internal(anyhow::anyhow!("Failed to open identity store: {}", e))
122 })?;
123
124 // Check if an identity with this name already exists
125 if store.exists_by_name(&self.name) {
126 return Err(CliError::IdentityAlreadyExists(self.name.clone()));
127 }
128
129 // Generate a new keypair
130 let keypair = KeyPair::generate();
131
132 // Build the identity
133 let mut builder = Identity::builder(&self.name)
134 .identity_type(self.parse_identity_type())
135 .usage(self.parse_usage());
136
137 if let Some(email) = &self.email {
138 builder = builder.email(email);
139 }
140
141 if let Some(description) = &self.description {
142 builder = builder.description(description);
143 }
144
145 // Use the keypair's public key for the identity
146 let identity = builder
147 .public_key(keypair.public.clone())
148 .build()
149 .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to create identity: {}", e)))?;
150
151 // Save the identity with its keypair
152 store
153 .save_with_keypair(&identity, &keypair, None)
154 .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to save identity: {}", e)))?;
155
156 // Set as default if requested
157 if self.set_default {
158 store.set_default(&identity.id).map_err(|e| {
159 CliError::Internal(anyhow::anyhow!("Failed to set as default: {}", e))
160 })?;
161 super::activate_server_for_identity(&identity.name);
162 }
163
164 if self.set_default_for_usage {
165 store
166 .set_default_for_usage(&identity.usage, &identity.id)
167 .map_err(|e| {
168 CliError::Internal(anyhow::anyhow!("Failed to set as default for usage: {}", e))
169 })?;
170 super::activate_server_for_identity(&identity.name);
171 }
172
173 // Print success message
174 print_success(&format!("Created identity: {}", self.name));
175 println!();

Callers

nothing calls this directly

Calls 15

print_successFunction · 0.85
print_hintFunction · 0.85
exists_by_nameMethod · 0.80
parse_identity_typeMethod · 0.80
parse_usageMethod · 0.80
emailMethod · 0.80
save_with_keypairMethod · 0.80
set_default_for_usageMethod · 0.80
cloneMethod · 0.45
usageMethod · 0.45
identity_typeMethod · 0.45

Tested by

no test coverage detected