Skip to content

Commit

Permalink
add structopt, make program able to parse multiple directories at once
Browse files Browse the repository at this point in the history
  • Loading branch information
aszecsei committed Feb 12, 2020
1 parent d77a3bf commit 8f297a3
Show file tree
Hide file tree
Showing 3 changed files with 230 additions and 11 deletions.
212 changes: 212 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ edition = "2018"

[dependencies]
walkdir = "2"
structopt = "0.3.9"

[profile.release]
incremental = false
lto = true
codegen-units = 1
codegen-units = 1
26 changes: 16 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{env, io, path};
use structopt::StructOpt;
use walkdir;

const SYMLINK_FOLLOW: bool = true;
Expand Down Expand Up @@ -204,23 +205,28 @@ fn pretty_size(size: u64) -> String {
format!("{:.1}{}", size, symbol)
}

#[derive(StructOpt, Debug)]
#[structopt(name = "kondo")]
struct Opt {
#[structopt(name = "DIRS", parse(from_os_str))]
/// The directory to examine
dirs: Vec<std::path::PathBuf>
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
use io::Write;
let dir = {
let mut args: Vec<String> = env::args().collect();
if args.len() == 2 {
path::PathBuf::from(args.pop().unwrap())
} else {
env::current_dir()?
}
};
let opt = Opt::from_args();
let dirs = if opt.dirs.is_empty() { vec![env::current_dir()?] } else { opt.dirs };

let stdout = io::stdout();
let mut write_handle = stdout.lock();

writeln!(&mut write_handle, "Scanning {:?}", dir)?;
let mut project_dirs = vec![];

let project_dirs = scan(&dir);
for dir in dirs {
writeln!(&mut write_handle, "Scanning {:?}", dir)?;
project_dirs.append(&mut scan(&dir));
}

writeln!(&mut write_handle, "{} projects found", project_dirs.len())?;

Expand Down

0 comments on commit 8f297a3

Please sign in to comment.