Skip to content

Commit

Permalink
feat: add seance option to graveyard subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesCranmer committed Apr 15, 2024
1 parent a1a9262 commit ad85c0f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ pub enum Commands {
},

/// Print the graveyard path
Graveyard,
Graveyard {
/// Get the graveyard subdirectory
/// of the current directory
#[arg(short, long)]
seance: bool,
},
}

struct IsDefault {
Expand Down
12 changes: 10 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use clap::Parser;
use std::env;
use std::io;
use std::process::ExitCode;

Expand All @@ -19,8 +20,15 @@ fn main() -> ExitCode {
}
return ExitCode::SUCCESS;
}
Some(Commands::Graveyard) => {
println!("{}", rip2::get_graveyard(None).display());
Some(Commands::Graveyard { seance }) => {
let graveyard = rip2::get_graveyard(None);
if *seance {
let cwd = &env::current_dir().unwrap();
let gravepath = util::join_absolute(graveyard, dunce::canonicalize(cwd).unwrap());
println!("{}", gravepath.display());
} else {
println!("{}", graveyard.display());
}
return ExitCode::SUCCESS;
}
None => {}
Expand Down
22 changes: 18 additions & 4 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,11 +678,25 @@ fn issue_0018() {
}

#[rstest]
fn test_graveyard_subcommand() {
fn test_graveyard_subcommand(
#[values(false, true)] seance: bool,
) {
let _env_lock = aquire_lock();

let expected_graveyard = rip2::get_graveyard(None);
let expected_graveyard_str = format!("{}\n", expected_graveyard.display());
cli_runner(["graveyard"], None)
let cwd = &env::current_dir().unwrap();
let expected_gravepath = util::join_absolute(&expected_graveyard, dunce::canonicalize(cwd).unwrap());
let expected_str = if seance {
format!("{}\n", expected_gravepath.display())
} else {
format!("{}\n", expected_graveyard.display())
};
let mut args = vec!["graveyard"];
if seance {
args.push("-s");
}
cli_runner(args, None)
.assert()
.success()
.stdout(is_match(expected_graveyard_str).unwrap());
.stdout(expected_str);
}

0 comments on commit ad85c0f

Please sign in to comment.