Skip to content
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
12 changes: 12 additions & 0 deletions FULL_HELP_DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1331,6 +1331,7 @@ Configure connection to networks
- `health` — Fetch the health of the configured RPC
- `info` — Checks the health of the configured RPC
- `settings` — Fetch the network's config settings
- `unset` — Unset the default network defined previously with `network use <network>`

## `stellar network add`

Expand Down Expand Up @@ -1486,6 +1487,17 @@ Fetch the network's config settings
- `--network-passphrase <NETWORK_PASSPHRASE>` — Network passphrase to sign the transaction sent to the rpc server
- `-n`, `--network <NETWORK>` — Name of network to use from config

## `stellar network unset`

Unset the default network defined previously with `network use <network>`

**Usage:** `stellar network unset [OPTIONS]`

###### **Options (Global):**

- `--global` — ⚠️ Deprecated: global config is always on
- `--config-dir <CONFIG_DIR>` — Location of config directory. By default, it uses `$XDG_CONFIG_HOME/stellar` if set, falling back to `~/.config/stellar` otherwise. Contains configuration files, aliases, and other persistent settings

## `stellar container`

Start local networks in containers
Expand Down
1 change: 1 addition & 0 deletions cmd/crates/soroban-test/tests/it/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod hello_world;
mod init;
mod keys;
mod ledger;
mod network;
mod secure_store;
mod snapshot;
mod tx;
Expand Down
54 changes: 54 additions & 0 deletions cmd/crates/soroban-test/tests/it/integration/network.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use predicates::prelude::{predicate, PredicateBooleanExt};
use soroban_test::TestEnv;

#[tokio::test]
#[allow(clippy::too_many_lines)]
async fn set_default_network() {
let sandbox = &TestEnv::new();

sandbox
.new_assert_cmd("network")
.arg("use")
.arg("testnet")
.assert()
.stderr(predicate::str::contains(
"The default network is set to `testnet`",
))
.success();
}

#[tokio::test]
#[allow(clippy::too_many_lines)]
async fn unset_default_network() {
let sandbox = &TestEnv::new();

sandbox
.new_assert_cmd("network")
.arg("use")
.arg("testnet")
.assert()
.success();

sandbox
.new_assert_cmd("env")
.env_remove("STELLAR_NETWORK")
.assert()
.stdout(predicate::str::contains("STELLAR_NETWORK=testnet"))
.success();

sandbox
.new_assert_cmd("network")
.arg("unset")
.assert()
.stderr(predicate::str::contains(
"The default network has been unset",
))
.success();

sandbox
.new_assert_cmd("env")
.env_remove("STELLAR_NETWORK")
.assert()
.stdout(predicate::str::contains("STELLAR_NETWORK=").not())
.success();
}
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/keys/unset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl Cmd {
pub fn run(&self, global_args: &global::Args) -> Result<(), Error> {
let printer = Print::new(global_args.quiet);

self.config_locator.unset_identity()?;
self.config_locator.unset_default_identity()?;

printer.infoln("The default source account has been unset".to_string());

Expand Down
8 changes: 8 additions & 0 deletions cmd/soroban-cli/src/commands/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub mod info;
pub mod ls;
pub mod rm;
pub mod settings;
pub mod unset;

#[derive(Debug, Parser)]
pub enum Cmd {
Expand All @@ -34,6 +35,9 @@ pub enum Cmd {

/// Fetch the network's config settings
Settings(settings::Cmd),

/// Unset the default network defined previously with `network use <network>`
Unset(unset::Cmd),
}

#[derive(thiserror::Error, Debug)]
Expand All @@ -58,6 +62,9 @@ pub enum Error {

#[error(transparent)]
Settings(#[from] settings::Error),

#[error(transparent)]
Unset(#[from] unset::Error),
}

impl Cmd {
Expand All @@ -70,6 +77,7 @@ impl Cmd {
Cmd::Health(cmd) => cmd.run(global_args).await?,
Cmd::Info(cmd) => cmd.run(global_args).await?,
Cmd::Settings(cmd) => cmd.run(global_args).await?,
Cmd::Unset(cmd) => cmd.run(global_args)?,
}
Ok(())
}
Expand Down
28 changes: 28 additions & 0 deletions cmd/soroban-cli/src/commands/network/unset.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use crate::{commands::global, print::Print};

use super::locator;

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Config(#[from] locator::Error),
}

#[derive(Debug, clap::Parser, Clone)]
#[group(skip)]
pub struct Cmd {
#[command(flatten)]
pub config_locator: locator::Args,
}

impl Cmd {
pub fn run(&self, global_args: &global::Args) -> Result<(), Error> {
let printer = Print::new(global_args.quiet);

self.config_locator.unset_default_network()?;

printer.infoln("The default network has been unset".to_string());

Ok(())
}
}
6 changes: 5 additions & 1 deletion cmd/soroban-cli/src/config/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,14 @@ impl Args {
Config::new()?.set_identity(name).save()
}

pub fn unset_identity(&self) -> Result<(), Error> {
pub fn unset_default_identity(&self) -> Result<(), Error> {
Config::new()?.unset_identity().save()
}

pub fn unset_default_network(&self) -> Result<(), Error> {
Config::new()?.unset_network().save()
}

pub fn list_identities(&self) -> Result<Vec<String>, Error> {
Ok(KeyType::Identity
.list_paths(&self.local_and_global()?)?
Expand Down
6 changes: 6 additions & 0 deletions cmd/soroban-cli/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ impl Config {
self
}

#[must_use]
pub fn unset_network(mut self) -> Self {
self.defaults.network = None;
self
}

pub fn save(&self) -> Result<(), locator::Error> {
let toml_string = toml::to_string(&self)?;
let path = cli_config_file()?;
Expand Down
Loading