Skip to content

Commit

Permalink
Do not fail when no env is defined.
Browse files Browse the repository at this point in the history
  • Loading branch information
fnando committed Nov 5, 2024
1 parent 73cf6ed commit e576173
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions cmd/soroban-cli/src/commands/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
locator::{self},
Config,
},
print::Print,
};
use clap::Parser;

Expand All @@ -17,13 +18,11 @@ pub struct Cmd {
pub enum Error {
#[error(transparent)]
Locator(#[from] locator::Error),

#[error("no defaults or environment variables set")]
NoEnv,
}

impl Cmd {
pub fn run(&self, _global_args: &global::Args) -> Result<(), Error> {
pub fn run(&self, global_args: &global::Args) -> Result<(), Error> {
let print = Print::new(global_args.quiet);
let config = Config::new()?;
let mut lines: Vec<(String, String)> = Vec::new();

Expand All @@ -36,11 +35,14 @@ impl Cmd {
}

if lines.is_empty() {
return Err(Error::NoEnv);
print.warnln("No defaults or environment variables set".to_string());
return Ok(());
}

let max_len = lines.iter().map(|l| l.0.len()).max().unwrap_or(0);

lines.sort();

for (value, source) in lines {
println!("{value:max_len$} # {source}");
}
Expand Down

0 comments on commit e576173

Please sign in to comment.