(&self)
| 116 | |
| 117 | impl 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!(); |
nothing calls this directly
no test coverage detected