Skip to content

Commit

Permalink
up dep
Browse files Browse the repository at this point in the history
  • Loading branch information
Antidote1911 committed Oct 2, 2023
1 parent c039baa commit 9e7ab6e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 25 deletions.
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "3.1.6", features = ["derive", "cargo"] }
serde = { version = "1.0", features = ["derive"] }
confy = "0.4"
color-eyre = "0.6.1"
clap = { version = "4.4.6", features = ["derive", "cargo"] }
serde = { version = "1.0.188", features = ["derive"] }
confy = "0.5.1"
color-eyre = "0.6.2"
question = "0.2.2"
libpassgen = "1.0.3"
# libpassgen = { git = "https://github.com/Antidote1911/libpassgen", branch = "master" }

[dev-dependencies]
assert_cmd = "1.0"
predicates = "1.0"
assert_cmd = "2.0.12"
predicates = "3.0.4"
13 changes: 8 additions & 5 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
use crate::config::Config;

use clap::{AppSettings, Parser};
use clap::Parser;
use libpassgen::{calculate_entropy, Pool};
use std::io::Write;

#[derive(Parser, Debug)]
#[clap(author, about, version,
after_help = "If you do not specify any of the \
#[clap(
author,
about,
version,
after_help = "If you do not specify any of the \
[--uppercase, --lowercase, --digits, --symbols, --others] flags, \
then uppercase, lowercase letters and digits will be used.",
setting = AppSettings::DeriveDisplayOrder)]
then uppercase, lowercase letters and digits will be used."
)]
pub struct Cli {
/// Use UPPERCASE letters [A-Z]
#[clap(short, long)]
Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ impl Config {
/// Creates a new instance with values from config file `/path/to/config/dir/crate_name/crate_name.toml`.
/// If file is missing or contains invalid values, then `Config::default()` is used.
pub fn new() -> Config {
confy::load(CRATE_NAME).unwrap_or_default()
confy::load(CRATE_NAME, None).unwrap_or_default()
}

/// Overwrites the config file with default values.
pub fn save_default() -> Result<(), ConfyError> {
confy::store(CRATE_NAME, Config::default())
confy::store(CRATE_NAME, None, Config::default())
}

// ----------------------- Getters ----------------------- //
Expand Down
18 changes: 13 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use libpassgen::{calculate_length, generate_n_passwords};
use std::io::stdout;
use std::{fs::File, io::LineWriter, io::Write};

use color_eyre::eyre::{Result, eyre};
use color_eyre::eyre::{eyre, Result};
use color_eyre::owo_colors::OwoColorize;

extern crate question;
Expand All @@ -27,7 +27,10 @@ fn run() -> Result<()> {

if opts.reset() {
Config::save_default().map_err(|e| eyre!(e))?;
println!("{}", "The default configuration was set successfully !".green());
println!(
"{}",
"The default configuration was set successfully !".green()
);
std::process::exit(0);
}

Expand All @@ -39,8 +42,8 @@ fn run() -> Result<()> {

let pass_vec = generate_n_passwords(&pool, length, opts.count());

for n in 0..opts.count() {
println!("{}", pass_vec[n].yellow());
for n in pass_vec.iter().take(opts.count()) {
println!("{}", n.yellow());
}

if opts.output().is_some() {
Expand All @@ -57,7 +60,12 @@ fn run() -> Result<()> {

if answer == Answer::YES {
writetxt(pass_vec, &dest).map_err(|e| eyre!(e))?;
println!("{} '{}' {}", "File".green(), opts.output().unwrap().green(), "was overwritten.".green());
println!(
"{} '{}' {}",
"File".green(),
opts.output().unwrap().green(),
"was overwritten.".green()
);
} else {
println!("{}", "Writting file canceled.".green());
}
Expand Down
13 changes: 6 additions & 7 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@ fn cmd() -> Command {
fn default_password_length_is_12() {
let mut cmd = cmd();
// the colored output add 10 to len of stdout
let predicate_fn = predicate::function(|x: &str| x.trim().len() == 12+10);
let predicate_fn = predicate::function(|x: &str| x.trim().len() == 12 + 10);

cmd.assert().success().stdout(predicate_fn);

}

#[test]
fn password_arg_length_100() {
let mut cmd = cmd();
cmd.args(&["-L", "100"]);
// the colored output add 10 to len of stdout
let predicate_fn = predicate::function(|x: &str| x.trim().len() == 100+10);
let predicate_fn = predicate::function(|x: &str| x.trim().len() == 100 + 10);

cmd.assert().success().stdout(predicate_fn);
}
Expand All @@ -33,7 +32,7 @@ fn created_10_passwords() {

let assert = cmd.assert().success();

let output = assert.get_output().stdout.as_slice().clone();
let output = assert.get_output().stdout.as_slice();
let reader = BufReader::new(output);

assert_eq!(reader.lines().count(), 10);
Expand All @@ -46,7 +45,7 @@ fn created_111_passwords() {

let assert = cmd.assert().success();

let output = assert.get_output().stdout.as_slice().clone();
let output = assert.get_output().stdout.as_slice();
let reader = BufReader::new(output);

assert_eq!(reader.lines().count(), 111);
Expand All @@ -55,9 +54,9 @@ fn created_111_passwords() {
#[test]
fn created_50_passwords_save_txt() {
let mut cmd = cmd();
cmd.args(&["-L", "6", "-c", "50","--output","/dev/null"]);
cmd.args(&["-L", "6", "-c", "50", "--output", "/dev/null"]);
// the colored output add 10 to len of stdout
let predicate_fn = predicate::str::contains("File Saved");

cmd.assert().success().stdout(predicate_fn);
}
}

0 comments on commit 9e7ab6e

Please sign in to comment.