Skip to content

Commit

Permalink
feat!: move config commands to top level
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Nov 16, 2023
1 parent 733ce06 commit 5b3cc5f
Show file tree
Hide file tree
Showing 21 changed files with 185 additions and 211 deletions.
6 changes: 3 additions & 3 deletions cmd/crates/soroban-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use assert_fs::{fixture::FixtureError, prelude::PathChild, TempDir};
use fs_extra::dir::CopyOptions;

use soroban_cli::{
commands::{config, contract, contract::invoke, global},
commands::{config, contract, contract::invoke, global, identity},
CommandParser, Pwd,
};

Expand Down Expand Up @@ -158,15 +158,15 @@ impl TestEnv {

/// Returns the public key corresponding to the test identity's `hd_path`
pub fn test_address(&self, hd_path: usize) -> String {
self.cmd::<config::identity::address::Cmd>(&format!("--hd-path={hd_path}"))
self.cmd::<identity::address::Cmd>(&format!("--hd-path={hd_path}"))
.public_key()
.unwrap()
.to_string()
}

/// Returns the private key corresponding to the test identity's `hd_path`
pub fn test_show(&self, hd_path: usize) -> String {
self.cmd::<config::identity::show::Cmd>(&format!("--hd-path={hd_path}"))
self.cmd::<identity::show::Cmd>(&format!("--hd-path={hd_path}"))
.private_key()
.unwrap()
.to_string()
Expand Down
38 changes: 13 additions & 25 deletions cmd/crates/soroban-test/tests/it/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use soroban_test::TestEnv;
use std::{fs, path::Path};

use crate::util::{add_identity, add_test_id, SecretKind, DEFAULT_SEED_PHRASE};
use soroban_cli::commands::config::network;
use soroban_cli::commands::network;

const NETWORK_PASSPHRASE: &str = "Local Sandbox Stellar Network ; September 2022";

Expand Down Expand Up @@ -32,8 +32,7 @@ fn set_and_remove_network() {
// .assert()
// .stdout("");
sandbox
.new_assert_cmd("config")
.arg("network")
.new_assert_cmd("network")
.arg("ls")
.assert()
.stdout("\n");
Expand All @@ -42,8 +41,7 @@ fn set_and_remove_network() {

fn add_network(sandbox: &TestEnv, name: &str) {
sandbox
.new_assert_cmd("config")
.arg("network")
.new_assert_cmd("network")
.arg("add")
.args([
"--rpc-url=https://127.0.0.1",
Expand All @@ -59,9 +57,8 @@ fn add_network(sandbox: &TestEnv, name: &str) {

fn add_network_global(sandbox: &TestEnv, dir: &Path, name: &str) {
sandbox
.new_assert_cmd("config")
.new_assert_cmd("network")
.env("XDG_CONFIG_HOME", dir.to_str().unwrap())
.arg("network")
.arg("add")
.arg("--global")
.arg("--rpc-url")
Expand All @@ -81,28 +78,25 @@ fn set_and_remove_global_network() {
add_network_global(&sandbox, &dir, "global");

sandbox
.new_assert_cmd("config")
.new_assert_cmd("network")
.env("XDG_CONFIG_HOME", dir.to_str().unwrap())
.arg("network")
.arg("ls")
.arg("--global")
.assert()
.stdout("global\n");

sandbox
.new_assert_cmd("config")
.new_assert_cmd("network")
.env("XDG_CONFIG_HOME", dir.to_str().unwrap())
.arg("network")
.arg("rm")
.arg("--global")
.arg("global")
.assert()
.stdout("");

sandbox
.new_assert_cmd("config")
.new_assert_cmd("network")
.env("XDG_CONFIG_HOME", dir.to_str().unwrap())
.arg("network")
.arg("ls")
.assert()
.stdout("\n");
Expand Down Expand Up @@ -150,8 +144,7 @@ fn read_identity() {
let ident_dir = dir.join(".soroban/identity");
assert!(ident_dir.exists());
sandbox
.new_assert_cmd("config")
.arg("identity")
.new_assert_cmd("identity")
.arg("ls")
.assert()
.stdout("test_id\n");
Expand All @@ -161,8 +154,7 @@ fn read_identity() {
fn generate_identity() {
let sandbox = TestEnv::default();
sandbox
.new_assert_cmd("config")
.arg("identity")
.new_assert_cmd("identity")
.arg("generate")
.arg("--seed")
.arg("0000000000000000")
Expand All @@ -172,8 +164,7 @@ fn generate_identity() {
.success();

sandbox
.new_assert_cmd("config")
.arg("identity")
.new_assert_cmd("identity")
.arg("ls")
.assert()
.stdout("test\n");
Expand All @@ -197,9 +188,8 @@ fn seed_phrase() {
);

sandbox
.new_assert_cmd("config")
.new_assert_cmd("id")
.current_dir(dir)
.arg("identity")
.arg("ls")
.assert()
.stdout("test_seed\n");
Expand All @@ -218,21 +208,19 @@ fn use_env() {
let sandbox = TestEnv::default();

sandbox
.new_assert_cmd("config")
.new_assert_cmd("identity")
.env(
"SOROBAN_SECRET_KEY",
"SDIY6AQQ75WMD4W46EYB7O6UYMHOCGQHLAQGQTKHDX4J2DYQCHVCQYFD",
)
.arg("identity")
.arg("add")
.arg("bob")
.assert()
.stdout("")
.success();

sandbox
.new_assert_cmd("config")
.arg("identity")
.new_assert_cmd("identity")
.arg("show")
.arg("bob")
.assert()
Expand Down
19 changes: 2 additions & 17 deletions cmd/soroban-cli/src/commands/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,20 @@ use crate::Pwd;

use self::{network::Network, secret::Secret};

pub mod identity;
use super::network;

pub mod locator;
pub mod network;
pub mod secret;

#[derive(Debug, Parser)]
pub enum Cmd {
/// Configure different identities to sign transactions.
#[command(subcommand)]
Identity(identity::Cmd),
/// Configure different networks
#[command(subcommand)]
Network(network::Cmd),
}

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Identity(#[from] identity::Error),
#[error(transparent)]
Network(#[from] network::Error),
#[error(transparent)]
Expand All @@ -34,16 +29,6 @@ pub enum Error {
Config(#[from] locator::Error),
}

impl Cmd {
pub async fn run(&self) -> Result<(), Error> {
match &self {
Cmd::Identity(identity) => identity.run().await?,
Cmd::Network(network) => network.run()?,
}
Ok(())
}
}

#[derive(Debug, clap::Args, Clone, Default)]
#[group(skip)]
pub struct Args {
Expand Down
6 changes: 2 additions & 4 deletions cmd/soroban-cli/src/commands/contract/bindings/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ use soroban_spec_typescript::{self as typescript, boilerplate::Project};
use crate::wasm;
use crate::{
commands::{
config::{
locator,
network::{self, Network},
},
config::locator,
contract::{self, fetch},
network::{self, Network},
},
utils::contract_spec::{self, ContractSpec},
};
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/contract/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use soroban_spec::read::FromWasmError;
use stellar_strkey::DecodeError;

use super::super::config::{self, locator};
use crate::commands::config::network::{self, Network};
use crate::commands::network::{self, Network};
use crate::{
rpc::{self, Client},
utils, Pwd,
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/contract/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl Cmd {
if let Some(mut val) = matches_.get_raw(&name) {
let mut s = val.next().unwrap().to_string_lossy().to_string();
if matches!(i.type_, ScSpecTypeDef::Address) {
let cmd = crate::commands::config::identity::address::Cmd {
let cmd = crate::commands::identity::address::Cmd {
name: Some(s.clone()),
hd_path: Some(0),
locator: self.config.locator.clone(),
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::io;

use soroban_env_host::xdr::{self, ReadXdr};

use super::config::{locator, network};
use super::{config::locator, network};
use crate::{rpc, utils};

#[derive(Parser, Debug, Clone)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::super::{locator, secret};
use clap::command;

use super::super::config::{locator, secret};

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::commands::config::secret::Secret;

use super::super::{locator, secret};
use super::super::config::{
locator,
secret::{self, Secret},
};
use clap::arg;

#[derive(thiserror::Error, Debug)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::command;

use crate::commands::config::network;
use crate::commands::network;

use super::address;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use clap::{arg, command};

use super::super::{
locator, network,
use crate::commands::network;

use super::super::config::{
locator,
secret::{self, Secret},
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::super::locator;
use clap::command;

use super::super::config::locator;

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::super::locator;
use clap::command;

use super::super::config::locator;

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::super::{locator, secret};
use clap::arg;

use super::super::config::{locator, secret};

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Expand Down
19 changes: 14 additions & 5 deletions cmd/soroban-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ pub mod config;
pub mod contract;
pub mod events;
pub mod global;
pub mod identity;
pub mod lab;
pub mod network;
pub mod plugin;
pub mod version;

Expand Down Expand Up @@ -91,11 +93,12 @@ impl Root {
pub async fn run(&mut self) -> Result<(), Error> {
match &mut self.cmd {
Cmd::Completion(completion) => completion.run(),
Cmd::Config(config) => config.run().await?,
Cmd::Contract(contract) => contract.run(&self.global_args).await?,
Cmd::Events(events) => events.run().await?,
Cmd::Lab(lab) => lab.run().await?,
Cmd::Network(network) => network.run()?,
Cmd::Version(version) => version.run(),
Cmd::Identity(id) => id.run().await?,
};
Ok(())
}
Expand All @@ -117,14 +120,17 @@ pub enum Cmd {
/// Tools for smart contract developers
#[command(subcommand)]
Contract(contract::Cmd),
/// Read and update config
#[command(subcommand)]
Config(config::Cmd),
/// Watch the network for contract events
Events(events::Cmd),
/// Create and manage identities including keys and addresses
#[command(subcommand, visible_alias = "id")]
Identity(identity::Cmd),
/// Experiment with early features and expert tools
#[command(subcommand)]
Lab(lab::Cmd),
/// Start and configure networks
#[command(subcommand)]
Network(network::Cmd),
/// Print version information
Version(version::Cmd),
}
Expand All @@ -136,7 +142,8 @@ pub enum Error {
Contract(#[from] contract::Error),
#[error(transparent)]
Events(#[from] events::Error),

#[error(transparent)]
Identity(#[from] identity::Error),
#[error(transparent)]
Lab(#[from] lab::Error),
#[error(transparent)]
Expand All @@ -145,4 +152,6 @@ pub enum Error {
Clap(#[from] clap::error::Error),
#[error(transparent)]
Plugin(#[from] plugin::Error),
#[error(transparent)]
Network(#[from] network::Error),
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{super::secret, locator};
use super::super::config::{locator, secret};
use clap::command;

#[derive(thiserror::Error, Debug)]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
rpc::{self, Client},
};

use super::locator;
use super::config::locator;

pub mod add;
pub mod ls;
Expand Down
File renamed without changes.
Loading

0 comments on commit 5b3cc5f

Please sign in to comment.