Skip to content

Commit

Permalink
fix: Add error-handling if configuration file is not exists.
Browse files Browse the repository at this point in the history
- Currently, 'info' command only
- Change pipe for Error type
  • Loading branch information
attakei committed Mar 20, 2024
1 parent 144792a commit f7cb049
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/commands/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
14 changes: 14 additions & 0 deletions tests/test_info.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f7cb049

Please sign in to comment.