Initial commit
Still getting Config and argument parsing setup.
This commit is contained in:
30
src/config.rs
Normal file
30
src/config.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
extern crate clap;
|
||||
use clap::{Arg, App};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Config {
|
||||
pub pattern: String,
|
||||
pub ignore_case: bool
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn from_args() -> Config {
|
||||
let matches = App::new("Rack")
|
||||
.version("0.1")
|
||||
.about("Like Ack but in Rust")
|
||||
.arg(Arg::with_name("ignore case")
|
||||
.short("i")
|
||||
.help("Ignore case when looking for matches"))
|
||||
.arg(Arg::with_name("pattern")
|
||||
.help("The pattern you're looking for")
|
||||
.index(1)
|
||||
.required(true))
|
||||
.get_matches();
|
||||
|
||||
Config {
|
||||
pattern: String::from(matches.value_of("pattern").unwrap()),
|
||||
ignore_case: matches.is_present("ignore case")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
31
src/main.rs
Normal file
31
src/main.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use std::env;
|
||||
use std::io;
|
||||
use std::fs::{self};
|
||||
use std::path::Path;
|
||||
|
||||
mod config;
|
||||
|
||||
fn main() {
|
||||
let config = config::Config::from_args();
|
||||
println!("{:?}", config);
|
||||
|
||||
let path = Path::new(".");
|
||||
|
||||
traverse_dir(path);
|
||||
}
|
||||
|
||||
fn parse_args() {
|
||||
}
|
||||
|
||||
fn traverse_dir(dir: &Path) -> io::Result<()> {
|
||||
for entry in fs::read_dir(dir)? {
|
||||
let entry = entry?;
|
||||
let file_type = entry.file_type()?;
|
||||
|
||||
if file_type.is_dir() {
|
||||
traverse_dir(&entry.path());
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user