diff --git a/homestar-runtime/src/cli.rs b/homestar-runtime/src/cli.rs index 65fcc1c2..5574510e 100644 --- a/homestar-runtime/src/cli.rs +++ b/homestar-runtime/src/cli.rs @@ -3,6 +3,7 @@ use crate::{ network::rpc::Client, runner::{file, response}, + KeyType, }; use anyhow::anyhow; use clap::{ArgGroup, Args, Parser, Subcommand}; @@ -21,8 +22,6 @@ pub use init::{handle_init_command, KeyArg, OutputMode}; pub(crate) mod show; pub use show::ConsoleTable; -use self::init::KeyTypeArg; - const DEFAULT_DB_PATH: &str = "homestar.db"; const TMP_DIR: &str = "/tmp"; const HELP_TEMPLATE: &str = "{name} {version} @@ -97,7 +96,7 @@ pub struct InitArgs { value_name = "KEY_TYPE", help = "The type of key to use for libp2p [optional]" )] - pub key_type: Option, + pub key_type: Option, /// The file to load the key from #[arg( long = "key-file", diff --git a/homestar-runtime/src/cli/init.rs b/homestar-runtime/src/cli/init.rs index fed2cfc7..5c022889 100644 --- a/homestar-runtime/src/cli/init.rs +++ b/homestar-runtime/src/cli/init.rs @@ -1,4 +1,3 @@ -use clap::ValueEnum; use inquire::{ui::RenderConfig, Confirm, CustomType, Select}; use miette::{bail, miette, Result}; use rand::Rng; @@ -54,13 +53,6 @@ pub enum KeyArg { }, } -/// The type of key to generate -#[derive(Debug, Clone, PartialEq, ValueEnum)] -pub enum KeyTypeArg { - Ed25519, - Secp256k1, -} - #[derive(Debug, Clone)] struct PubkeySeed([u8; 32]); @@ -228,13 +220,12 @@ fn handle_output_mode( } fn handle_key_type( - key_type: Option, + key_type: Option, no_input: bool, _writer: &mut Box, ) -> Result { match key_type { - Some(KeyTypeArg::Ed25519) => Ok(KeyType::Ed25519), - Some(KeyTypeArg::Secp256k1) => Ok(KeyType::Secp256k1), + Some(key_type) => Ok(key_type), None => { if no_input { bail!("Aborting... cannot prompt for key type in non-interactive mode. Pass `--key-type ` to set it."); diff --git a/homestar-runtime/src/settings/pubkey_config.rs b/homestar-runtime/src/settings/pubkey_config.rs index 2c53121f..024ab357 100644 --- a/homestar-runtime/src/settings/pubkey_config.rs +++ b/homestar-runtime/src/settings/pubkey_config.rs @@ -1,6 +1,7 @@ //! Pubkey configuration. use anyhow::{anyhow, Context}; +use clap::ValueEnum; use libp2p::{identity, identity::secp256k1}; use rand::{Rng, SeedableRng}; use sec1::der::Decode; @@ -28,7 +29,7 @@ pub enum PubkeyConfig { } /// Supported key types of homestar -#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq)] +#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, ValueEnum)] pub enum KeyType { /// Ed25519 key #[default]