transformed into workspace
This commit is contained in:
parent
6c96dcb2b1
commit
9f0f94a9f5
10
Cargo.lock
generated
10
Cargo.lock
generated
@ -101,7 +101,7 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "catdex"
|
||||
name = "cat_cli"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
@ -111,6 +111,14 @@ dependencies = [
|
||||
"predicates",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "catdex"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"cat_cli",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.39"
|
||||
|
||||
15
Cargo.toml
15
Cargo.toml
@ -1,13 +1,2 @@
|
||||
[package]
|
||||
name = "catdex"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.98"
|
||||
clap = { version = "4.5.39", features = ["derive"] }
|
||||
colored = "3.0.0"
|
||||
|
||||
[dev-dependencies]
|
||||
predicates = "3.1.3"
|
||||
assert_cmd = "2.0.17"
|
||||
[workspace]
|
||||
members = ["cat_cli", "catdex"]
|
||||
|
||||
13
cat_cli/Cargo.toml
Normal file
13
cat_cli/Cargo.toml
Normal file
@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "cat_cli"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.98"
|
||||
clap = { version = "4.5.39", features = ["derive"] }
|
||||
colored = "3.0.0"
|
||||
|
||||
[dev-dependencies]
|
||||
predicates = "3.1.3"
|
||||
assert_cmd = "2.0.17"
|
||||
@ -7,9 +7,9 @@ use anyhow::Error;
|
||||
use clap::Parser;
|
||||
use colored::Colorize;
|
||||
|
||||
use crate::cli::img::{cat_picture, woof_err};
|
||||
use crate::img::{cat_picture, woof_err};
|
||||
|
||||
#[derive(Parser)]
|
||||
#[derive(Parser, Debug)]
|
||||
struct Options {
|
||||
#[clap(default_value = "Meow!")]
|
||||
/// what might the cat say?
|
||||
@ -40,39 +40,27 @@ fn get_message(options: &mut Options) -> Result<String, Error> {
|
||||
}
|
||||
|
||||
pub fn run_cli() -> Result<(), Error> {
|
||||
let mut options = Options::parse();
|
||||
run_cli_with_args(Options::parse())
|
||||
}
|
||||
|
||||
fn run_cli_with_args(mut options: Options) -> Result<(), Error> {
|
||||
let message = get_message(&mut options)?;
|
||||
woof_err(&message);
|
||||
// get picture before printing message - this way if theres an error it gets printed first
|
||||
let cat_picture = cat_picture(options.file, options.dead)?;
|
||||
woof_err(&message);
|
||||
println!("{}", format_msg(&message));
|
||||
println!("{}", cat_picture);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_with_defaults() {
|
||||
assert_cmd::Command::cargo_bin("catdex")
|
||||
.expect("binary_exists")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicates::str::contains("Meow"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fail_on_missing_file() {
|
||||
assert_cmd::Command::cargo_bin("catdex")
|
||||
.expect("binary_exists")
|
||||
.args(["-f", "whatever"])
|
||||
.assert()
|
||||
.failure();
|
||||
let options = Options::parse_from(["cat_cli", "-f", "whatever"]);
|
||||
assert!(run_cli_with_args(options).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn succes_file() {
|
||||
assert_cmd::Command::cargo_bin("catdex")
|
||||
.expect("binary_exists")
|
||||
.args(["-f", "resources/cat1"])
|
||||
.assert()
|
||||
.success();
|
||||
let options = Options::parse_from(["cat_cli", "-f", "../resources/cat1"]);
|
||||
assert!(run_cli_with_args(options).is_ok());
|
||||
}
|
||||
8
catdex/Cargo.toml
Normal file
8
catdex/Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "catdex"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.98"
|
||||
cat_cli = { path = "../cat_cli" }
|
||||
8
catdex/src/main.rs
Normal file
8
catdex/src/main.rs
Normal file
@ -0,0 +1,8 @@
|
||||
use anyhow::Error;
|
||||
use cat_cli::run::run_cli;
|
||||
|
||||
fn main() -> Result<(), Error> {
|
||||
run_cli()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -1 +0,0 @@
|
||||
|
||||
@ -1 +1,2 @@
|
||||
pub mod cli;
|
||||
pub mod cat_cli;
|
||||
pub mod tui;
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
use anyhow::Error;
|
||||
use catdex::cli::run::run_cli;
|
||||
|
||||
fn main() -> Result<(), Error> {
|
||||
unsafe { std::env::set_var("CLICOLOR_FORCE", "1") };
|
||||
run_cli()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user