Skip to content

Commit

Permalink
refactor: remove KeyTypeArg in favor of using KeyType
Browse files Browse the repository at this point in the history
  • Loading branch information
QuinnWilton committed Feb 27, 2024
1 parent f80566e commit 71ec5f3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
5 changes: 2 additions & 3 deletions homestar-runtime/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use crate::{
network::rpc::Client,
runner::{file, response},
KeyType,
};
use anyhow::anyhow;
use clap::{ArgGroup, Args, Parser, Subcommand};
Expand All @@ -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}
Expand Down Expand Up @@ -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<KeyTypeArg>,
pub key_type: Option<KeyType>,
/// The file to load the key from
#[arg(
long = "key-file",
Expand Down
13 changes: 2 additions & 11 deletions homestar-runtime/src/cli/init.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use clap::ValueEnum;
use inquire::{ui::RenderConfig, Confirm, CustomType, Select};
use miette::{bail, miette, Result};
use rand::Rng;
Expand Down Expand Up @@ -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]);

Expand Down Expand Up @@ -228,13 +220,12 @@ fn handle_output_mode(
}

fn handle_key_type(
key_type: Option<KeyTypeArg>,
key_type: Option<KeyType>,
no_input: bool,
_writer: &mut Box<dyn Write>,
) -> Result<KeyType> {
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 <KEY_TYPE>` to set it.");
Expand Down
3 changes: 2 additions & 1 deletion homestar-runtime/src/settings/pubkey_config.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 71ec5f3

Please sign in to comment.