Skip to content

Commit f432d97

Browse files
committed
refactor: project structure
1 parent e16a61b commit f432d97

7 files changed

Lines changed: 51 additions & 40 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/target
22
/fixtures
3+
output.*

src/opts.rs renamed to src/cli/csv_opts.rs

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,7 @@
1-
use std::fmt;
2-
use std::{path::Path, str::FromStr};
1+
use std::{fmt, path::Path, str::FromStr};
32

43
use clap::Parser;
54

6-
#[derive(Debug, Parser)]
7-
#[command(name = "rcli", version, author, about, long_about = None)]
8-
pub struct Opts {
9-
#[command(subcommand)]
10-
pub cmd: SubCommand,
11-
}
12-
13-
#[derive(Debug, Parser)]
14-
pub enum SubCommand {
15-
#[command(name = "csv", about = "Show CSV, or convert CSV to other formats")]
16-
Csv(CsvOpts),
17-
18-
#[command(name = "genpass", about = "Generate a random password")]
19-
GenPass(GenPassOpts),
20-
}
21-
225
#[derive(Debug, Clone, Copy)]
236
pub enum OutputFormat {
247
Json,
@@ -78,24 +61,6 @@ pub struct CsvOpts {
7861
pub delimiter: char,
7962
}
8063

81-
#[derive(Debug, Parser)]
82-
pub struct GenPassOpts {
83-
#[arg(short, long, help = "Length of the password", default_value_t = 12)]
84-
pub length: u8,
85-
86-
#[arg(long = "no-uppercase", help = "Exclude uppercase characters", default_value_t = true, action = clap::ArgAction::SetFalse)]
87-
pub uppercase: bool,
88-
89-
#[arg(long = "no-lowercase", help = "Exclude lowercase characters", default_value_t = true, action = clap::ArgAction::SetFalse)]
90-
pub lowercase: bool,
91-
92-
#[arg(long = "no-numbers", help = "Exclude numbers", default_value_t = true, action = clap::ArgAction::SetFalse)]
93-
pub numbers: bool,
94-
95-
#[arg(long = "no-special", help = "Exclude special characters", default_value_t = true, action = clap::ArgAction::SetFalse)]
96-
pub special: bool,
97-
}
98-
9964
fn verify_input_file(filename: &str) -> Result<String, String> {
10065
if Path::new(filename).exists() {
10166
Ok(filename.to_string())

src/cli/genpass_opts.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use clap::Parser;
2+
3+
#[derive(Debug, Parser)]
4+
pub struct GenPassOpts {
5+
#[arg(short, long, help = "Length of the password", default_value_t = 12)]
6+
pub length: u8,
7+
8+
#[arg(long = "no-uppercase", help = "Exclude uppercase characters", default_value_t = true, action = clap::ArgAction::SetFalse)]
9+
pub uppercase: bool,
10+
11+
#[arg(long = "no-lowercase", help = "Exclude lowercase characters", default_value_t = true, action = clap::ArgAction::SetFalse)]
12+
pub lowercase: bool,
13+
14+
#[arg(long = "no-numbers", help = "Exclude numbers", default_value_t = true, action = clap::ArgAction::SetFalse)]
15+
pub numbers: bool,
16+
17+
#[arg(long = "no-special", help = "Exclude special characters", default_value_t = true, action = clap::ArgAction::SetFalse)]
18+
pub special: bool,
19+
}

src/cli/mod.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
mod csv_opts;
2+
mod genpass_opts;
3+
4+
use clap::Parser;
5+
6+
pub use self::{
7+
csv_opts::{CsvOpts, OutputFormat},
8+
genpass_opts::GenPassOpts,
9+
};
10+
11+
#[derive(Debug, Parser)]
12+
#[command(name = "rcli", version, author, about, long_about = None)]
13+
pub struct Opts {
14+
#[command(subcommand)]
15+
pub cmd: SubCommand,
16+
}
17+
18+
#[derive(Debug, Parser)]
19+
pub enum SubCommand {
20+
#[command(name = "csv", about = "Show CSV, or convert CSV to other formats")]
21+
Csv(CsvOpts),
22+
23+
#[command(name = "genpass", about = "Generate a random password")]
24+
GenPass(GenPassOpts),
25+
}

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
mod opts;
1+
mod cli;
22
mod process;
33

4-
pub use opts::{GenPassOpts, Opts, SubCommand};
4+
pub use cli::{Opts, SubCommand};
55
pub use process::*;

src/process/csv.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ use csv::Reader;
44
use serde::{Deserialize, Serialize};
55
use serde_json::Value;
66

7-
use crate::opts::{CsvOpts, OutputFormat};
87
use anyhow::Ok;
98

9+
use crate::cli::{CsvOpts, OutputFormat};
10+
1011
const TOML_ROOT_KEY: &str = "data";
1112

1213
#[allow(dead_code)]

src/process/gen_pass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rand::{Rng, seq::SliceRandom};
22
use zxcvbn::zxcvbn;
33

4-
use crate::opts::GenPassOpts;
4+
use crate::cli::GenPassOpts;
55

66
const UPPER_CHARSET: &[u8] = b"ABCDEFGHJKLMNPQRSTUVWXYZ";
77
const LOWER_CHARSET: &[u8] = b"abcdefghijkmnopqrstuvwxyz";

0 commit comments

Comments
 (0)