diff --git a/src/commands/info.rs b/src/commands/info.rs index 1985787..24c2a3f 100644 --- a/src/commands/info.rs +++ b/src/commands/info.rs @@ -3,13 +3,16 @@ use crate::config; use crate::versioning; -use anyhow::Result; +use anyhow::{anyhow, Result}; use clap::Args; #[derive(Args)] pub(crate) struct Arguments {} pub(crate) fn execute(_args: &Arguments) -> Result<()> { + if config::find_config_path().is_none() { + return Err(anyhow!("Configuratio file is not exists.")); + } // Load config file. let config_data = config::load_config().unwrap(); println!("# Version info"); diff --git a/src/main.rs b/src/main.rs index 9b5e034..9f22c51 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,11 +7,12 @@ use crate::commands::run_command; fn main() { let result = run_command(); - match result { + let return_code = match result { Ok(()) => 0, Err(err) => { - println!("{err}"); + eprintln!("{err}"); 1 } }; + std::process::exit(return_code); } diff --git a/tests/test_info.py b/tests/test_info.py new file mode 100644 index 0000000..16129c9 --- /dev/null +++ b/tests/test_info.py @@ -0,0 +1,14 @@ +"""Test case for ``age info``.""" + +from pathlib import Path +from subprocess import PIPE, run + + +def test_not_configured_env(target_bin: str, tmp_path: Path): + """'info' command requires configuration file. + + If age does not find configuration file, it should display message. + """ + proc = run([target_bin, "info"], stdout=PIPE, stderr=PIPE, text=True, cwd=tmp_path) + assert proc.returncode == 1 + assert "not exists." in proc.stderr