Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: polishes #2171

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions autonomi_cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ pub async fn handle_subcommand(opt: Opt) -> Result<()> {
FileCmd::List => file::list(peers),
},
SubCmd::Register { command } => match command {
RegisterCmd::Cost { name } => register::cost(&name, peers).await,
RegisterCmd::Create { name, value } => register::create(&name, &value, peers).await,
RegisterCmd::Edit { name, value } => register::edit(&name, &value, peers).await,
RegisterCmd::Get { name } => register::get(&name, peers).await,
RegisterCmd::Cost { name } => register::cost(&name, peers),
RegisterCmd::Create { name, value } => register::create(&name, &value, peers),
RegisterCmd::Edit { name, value } => register::edit(&name, &value, peers),
RegisterCmd::Get { name } => register::get(&name, peers),
RegisterCmd::List => register::list(peers),
},
SubCmd::Vault { command } => match command {
Expand Down
2 changes: 1 addition & 1 deletion autonomi_cli/src/commands/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ pub async fn download(addr: &str, dest_path: &str, peers: Vec<Multiaddr>) -> Res
}

pub fn list(_peers: Vec<Multiaddr>) -> Result<()> {
println!("Listing previous uploads...");
println!("The file list feature is coming soon!");
Ok(())
}
34 changes: 14 additions & 20 deletions autonomi_cli/src/commands/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,37 @@ use autonomi::Multiaddr;
use color_eyre::eyre::Context;
use color_eyre::eyre::Result;

#[expect(clippy::unused_async)]
pub async fn cost(name: &str, _peers: Vec<Multiaddr>) -> Result<()> {
let register_key = crate::utils::get_register_signing_key()
pub fn cost(_name: &str, _peers: Vec<Multiaddr>) -> Result<()> {
let _register_key = crate::utils::get_register_signing_key()
.wrap_err("The register key is required to perform this action")?;
println!("Estimate cost to register name: {name} with register key: {register_key}");
println!("The register feature is coming soon!");
Ok(())
}

#[expect(clippy::unused_async)]
pub async fn create(name: &str, value: &str, _peers: Vec<Multiaddr>) -> Result<()> {
let secret_key = crate::utils::get_secret_key()
pub fn create(_name: &str, _value: &str, _peers: Vec<Multiaddr>) -> Result<()> {
let _secret_key = crate::utils::get_secret_key()
.wrap_err("The secret key is required to perform this action")?;
let register_key = crate::utils::get_register_signing_key()
let _register_key = crate::utils::get_register_signing_key()
.wrap_err("The register key is required to perform this action")?;
println!(
"Creating register: {name} with value: {value} using secret key: {secret_key} and register key: {register_key}"
);
println!("The register feature is coming soon!");
Ok(())
}

#[expect(clippy::unused_async)]
pub async fn edit(name: &str, value: &str, _peers: Vec<Multiaddr>) -> Result<()> {
let register_key = crate::utils::get_register_signing_key()
pub fn edit(_name: &str, _value: &str, _peers: Vec<Multiaddr>) -> Result<()> {
let _register_key = crate::utils::get_register_signing_key()
.wrap_err("The register key is required to perform this action")?;
println!("Editing register: {name} with value: {value} using register key: {register_key}");
println!("The register feature is coming soon!");
Ok(())
}

#[expect(clippy::unused_async)]
pub async fn get(name: &str, _peers: Vec<Multiaddr>) -> Result<()> {
let register_key = crate::utils::get_register_signing_key()
pub fn get(_name: &str, _peers: Vec<Multiaddr>) -> Result<()> {
let _register_key = crate::utils::get_register_signing_key()
.wrap_err("The register key is required to perform this action")?;
println!("Getting value of register: {name} with register key: {register_key}");
println!("The register feature is coming soon!");
Ok(())
}

pub fn list(_peers: Vec<Multiaddr>) -> Result<()> {
println!("Listing previous registers...");
println!("The register feature is coming soon!");
Ok(())
}
11 changes: 5 additions & 6 deletions autonomi_cli/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn get_secret_key() -> Result<String> {
// load the key from file
let key_path = dir.join(SECRET_KEY_FILE);
fs::read_to_string(&key_path)
.wrap_err("Failed to read secret key from file".to_string())
.wrap_err("Failed to read secret key from file")
.with_suggestion(|| format!("make sure you've provided the {SECRET_KEY} env var or have the key in a file at {key_path:?}"))
}

Expand All @@ -63,7 +63,7 @@ pub fn get_register_signing_key() -> Result<String> {
// load the key from file
let key_path = dir.join(REGISTER_SIGNING_KEY_FILE);
fs::read_to_string(&key_path)
.wrap_err("Failed to read secret key from file".to_string())
.wrap_err("Failed to read secret key from file")
.with_suggestion(|| format!("make sure you've provided the {REGISTER_SIGNING_KEY} env var or have the key in a file at {key_path:?}"))
}

Expand All @@ -72,16 +72,15 @@ pub fn get_client_data_dir_path() -> Result<PathBuf> {
.ok_or_else(|| eyre!("Failed to obtain data dir, your OS might not be supported."))?;
home_dirs.push("safe");
home_dirs.push("client");
std::fs::create_dir_all(home_dirs.as_path())
.wrap_err("Failed to create data dir".to_string())?;
std::fs::create_dir_all(home_dirs.as_path()).wrap_err("Failed to create data dir")?;
Ok(home_dirs)
}

pub async fn get_peers(peers: PeersArgs) -> Result<Vec<Multiaddr>> {
peers.get_peers().await
.wrap_err("Please provide valid Network peers to connect to".to_string())
.wrap_err("Please provide valid Network peers to connect to")
.with_suggestion(|| format!("make sure you've provided network peers using the --peers option or the {SAFE_PEERS_ENV} env var"))
.with_suggestion(|| "a peer address looks like this: /ip4/42.42.42.42/udp/4242/quic-v1/p2p/B64nodePeerIDvdjb3FAJF4ks3moreBase64CharsHere".to_string())
.with_suggestion(|| "a peer address looks like this: /ip4/42.42.42.42/udp/4242/quic-v1/p2p/B64nodePeerIDvdjb3FAJF4ks3moreBase64CharsHere")
}

pub(crate) fn get_evm_network_from_environment() -> Result<Network> {
Expand Down
Loading