Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 3e91047

Browse files
authored
token-cli: produce error if invalid --config option (#3166)
* token-cli: produce error if invalid --config option * token-cli: add test for invalid --config
1 parent 5b1b87e commit 3e91047

File tree

3 files changed

+87
-2
lines changed

3 files changed

+87
-2
lines changed

Cargo.lock

Lines changed: 68 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

token/cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ spl-memo = { version = "3.0.1", path="../../memo/program", features = ["no-entry
3333

3434
[dev-dependencies]
3535
solana-test-validator = "=1.10.19"
36+
assert_cmd = "2.0.4"
3637

3738
[[bin]]
3839
name = "spl-token"

token/cli/src/main.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2539,7 +2539,10 @@ fn main() -> Result<(), Error> {
25392539

25402540
let config = {
25412541
let cli_config = if let Some(config_file) = matches.value_of("config_file") {
2542-
solana_cli_config::Config::load(config_file).unwrap_or_default()
2542+
solana_cli_config::Config::load(config_file).unwrap_or_else(|_| {
2543+
eprintln!("error: Could not find config file `{}`", config_file);
2544+
exit(1);
2545+
})
25432546
} else {
25442547
solana_cli_config::Config::default()
25452548
};
@@ -3138,13 +3141,14 @@ fn handle_tx(
31383141
mod tests {
31393142
use {
31403143
super::*,
3144+
assert_cmd::prelude::*,
31413145
solana_client::blockhash_query::Source,
31423146
solana_sdk::{
31433147
bpf_loader,
31443148
signature::{Keypair, Signer},
31453149
},
31463150
solana_test_validator::{ProgramInfo, TestValidator, TestValidatorGenesis},
3147-
std::path::PathBuf,
3151+
std::{path::PathBuf, process::Command},
31483152
};
31493153

31503154
fn clone_keypair(keypair: &Keypair) -> Keypair {
@@ -3633,4 +3637,16 @@ mod tests {
36333637
assert_eq!(ui_account.mint, token.to_string());
36343638
assert_eq!(ui_account.owner, aux_string);
36353639
}
3640+
3641+
#[test]
3642+
fn invalid_config_will_cause_commands_to_fail() {
3643+
let mut cmd = Command::cargo_bin("spl-token").unwrap();
3644+
let args = &["address", "--config", "~/nonexistent/config.yml"];
3645+
3646+
cmd.args(args)
3647+
.assert()
3648+
.stderr("error: Could not find config file `~/nonexistent/config.yml`\n");
3649+
3650+
cmd.args(args).assert().code(1).failure();
3651+
}
36363652
}

0 commit comments

Comments
 (0)