Skip to content

Commit 51b68cc

Browse files
committed
Add scaffolding for the 'scan' functionality
1 parent d290d74 commit 51b68cc

3 files changed

Lines changed: 62 additions & 1 deletion

File tree

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@
44
artifacts and cleans them up safely. It supports many common languages and build
55
systems including Rust, Node.js, Python, Java, and more.
66

7+
## Usage
8+
9+
```
10+
> crafty help
11+
A command-line tool that scans projects for large build artifacts and cleans them up
12+
13+
Usage: crufty <COMMAND>
14+
15+
Commands:
16+
scan Scan for build artifacts in the current directory
17+
help Print this message or the help of the given subcommand(s)
18+
19+
Options:
20+
-h, --help Print help
21+
-V, --version Print version
22+
```
23+
724
## Usage example
825

926
### Basic Scan

src/crufty.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
1+
#![allow(dead_code)]
2+
use std::path::PathBuf;
3+
14
pub mod cli;
5+
6+
pub struct ArtifactCandidate {
7+
path: PathBuf,
8+
size: Option<u64>,
9+
}
10+
11+
pub fn fetch_artifacts(_path : &PathBuf) -> Vec<ArtifactCandidate> {
12+
vec![]
13+
}

src/main.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
1+
use clap::Parser;
2+
use console::{style, Term};
3+
use crufty::cli::{Cli, Commands};
4+
use crufty::fetch_artifacts;
5+
use std::env;
6+
use std::io;
7+
use std::process;
18

29
mod crufty;
10+
311
fn main() {
4-
println!("Crufty!");
12+
let cli = Cli::parse();
13+
14+
match &cli.command {
15+
Commands::Scan => match scan() {
16+
Err(err) => exit_unrecoverable(err),
17+
Ok(_) => {}
18+
},
19+
}
20+
}
21+
22+
fn scan() -> io::Result<()> {
23+
let term = Term::stdout();
24+
let path = env::current_dir()?;
25+
term
26+
.write_line(&format!("[+] Scanning: {}", style(path.display()).bold()))?;
27+
term.write_line("")?;
28+
let _ = fetch_artifacts(&path);
29+
Ok(())
30+
}
31+
32+
fn exit_unrecoverable(_err: io::Error) {
33+
let term_err = Term::stdout();
34+
let error_message = "Encountered error, existing...";
35+
let _ = term_err.write_line(&format!("{}", error_message));
36+
process::exit(1);
537
}

0 commit comments

Comments
 (0)