wip on cli args

This commit is contained in:
Cyryl Płotnicki 2025-04-18 20:52:37 +01:00
parent aa205f43a6
commit 6d7778c1a8
4 changed files with 443 additions and 210 deletions

601
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -9,6 +9,7 @@ description = "modern and simple, yet efficient backup solution"
[dependencies]
anyhow = "1.0"
argh = "0.1"
base64 = "0.22"
blake = "2"
chacha20poly1305 = "0.10"
@ -18,7 +19,6 @@ hex = "0.4"
log = "0.4"
rand = "0.8"
reed-solomon = "0.2"
seahorse = "2"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1"
sha2 = "0.10"
@ -32,7 +32,9 @@ default-features = false
features = ["process"]
[dev-dependencies]
assert_cmd = "2"
criterion = "0.5"
predicates = "3"
pretty_assertions = "1"
proptest = "1"
two-rusty-forks = "0.4"
@ -40,7 +42,14 @@ two-rusty-forks = "0.4"
[dev-dependencies.cargo-husky]
version = "1"
default-features = false
features = ["run-for-all", "prepush-hook", "run-cargo-check", "run-cargo-test", "run-cargo-clippy", "run-cargo-fmt"]
features = [
"run-for-all",
"prepush-hook",
"run-cargo-check",
"run-cargo-test",
"run-cargo-clippy",
"run-cargo-fmt",
]
[[bench]]
name = "bench"
@ -50,4 +59,4 @@ harness = false
debug = 1
[features]
failpoints = [ "fail/failpoints" ]
failpoints = ["fail/failpoints"]

View file

@ -1,13 +1,18 @@
use seahorse::App;
use std::env;
use argh::FromArgs;
use std::path::PathBuf;
#[derive(FromArgs, PartialEq, Debug)]
/// Options for the program.
struct Options {
#[argh(positional)]
pub source: PathBuf,
#[argh(positional)]
pub destination: PathBuf,
}
fn main() {
let args: Vec<String> = env::args().collect();
let app = App::new(env!("CARGO_PKG_NAME"))
.description(env!("CARGO_PKG_DESCRIPTION"))
.author(env!("CARGO_PKG_AUTHORS"))
.version(env!("CARGO_PKG_VERSION"))
.action(|c| println!("Hello, {:?}", c.args));
let options: Options = argh::from_env();
app.run(args);
println!("Source: {}", options.source.display());
println!("Destination: {}", options.destination.display());
}

14
tests/cli_tests.rs Normal file
View file

@ -0,0 +1,14 @@
use assert_cmd::prelude::*;
use predicates::prelude::*;
use std::process::Command;
#[test]
fn fails_without_arguments() -> Result<(), Box<dyn std::error::Error>> {
let mut cmd = Command::cargo_bin("bakare")?;
cmd.assert()
.failure()
.stderr(predicate::str::contains("Required positional arguments not provided:"));
Ok(())
}