Added command line argument parsing.
This commit is contained in:
parent
5abe93a0dc
commit
e6570cf4b7
8 changed files with 103 additions and 62 deletions
|
@ -6,3 +6,4 @@ edition = "2018"
|
|||
|
||||
[dependencies]
|
||||
uuid = { version = "0.7", features = ["serde", "v4"] }
|
||||
clap = { version = "~2.27.0", features = ["yaml"] }
|
9
gemla/cli.yml
Normal file
9
gemla/cli.yml
Normal file
|
@ -0,0 +1,9 @@
|
|||
name: GEMLA
|
||||
version: "0.1"
|
||||
autor: Jacob VanDomelen <jacob.vandome15@gmail.com>
|
||||
about: Uses a genetic algorithm to generate a machine learning algorithm.
|
||||
args:
|
||||
- DIRECTORY:
|
||||
help: Sets the input/output directory for the program.
|
||||
required: true
|
||||
index: 1
|
|
@ -3,11 +3,16 @@ mod state;
|
|||
|
||||
use uuid::Uuid;
|
||||
|
||||
// pub struct Bracket {
|
||||
// tree: tree::Tree,
|
||||
// directory: String
|
||||
// }
|
||||
|
||||
fn build_tree(h: u32) -> Option<Box<tree::Tree>> {
|
||||
let mut result: Option<Box<tree::Tree>> = None;
|
||||
|
||||
if h != 0 {
|
||||
result = Some(tree::concat_trees(Uuid::new_v4(), build_tree(h - 1), build_tree(h - 1)));
|
||||
result = Some(Box::new(tree::combine_trees(Uuid::new_v4(), build_tree(h - 1), build_tree(h - 1))));
|
||||
match &result {
|
||||
Some(r) => (*r).run_simulation(),
|
||||
_ => ()
|
||||
|
@ -25,7 +30,11 @@ pub fn run_bracket() {
|
|||
println!("=========================================");
|
||||
println!("Running bracket...");
|
||||
height += 1;
|
||||
tree = *tree::concat_trees(Uuid::new_v4(), Some(Box::new(tree)), build_tree(height));
|
||||
tree = tree::combine_trees(Uuid::new_v4(), Some(Box::new(tree)), build_tree(height));
|
||||
tree.run_simulation();
|
||||
|
||||
if height == 3 {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,18 +1,18 @@
|
|||
use uuid::Uuid;
|
||||
use std::fmt;
|
||||
// use uuid::Uuid;
|
||||
// use std::fmt;
|
||||
|
||||
pub struct State {
|
||||
id: Uuid
|
||||
}
|
||||
// pub struct State {
|
||||
// id: Uuid
|
||||
// }
|
||||
|
||||
impl fmt::Display for State {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.id)
|
||||
}
|
||||
}
|
||||
// impl fmt::Display for State {
|
||||
// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
// write!(f, "{}", self.id)
|
||||
// }
|
||||
// }
|
||||
|
||||
pub fn create(id: &Uuid) -> State {
|
||||
State {
|
||||
id: id.clone()
|
||||
}
|
||||
}
|
||||
// pub fn create(id: &Uuid) -> State {
|
||||
// State {
|
||||
// id: id.clone()
|
||||
// }
|
||||
// }
|
|
@ -7,12 +7,12 @@ pub struct Tree {
|
|||
right: Option<Box<Tree>>
|
||||
}
|
||||
|
||||
pub fn concat_trees(id: Uuid, l: Option<Box<Tree>>, r: Option<Box<Tree>>) -> Box<Tree> {
|
||||
Box::new(Tree {
|
||||
pub fn combine_trees(id: Uuid, l: Option<Box<Tree>>, r: Option<Box<Tree>>) -> Tree {
|
||||
Tree {
|
||||
id: id,
|
||||
left: l,
|
||||
right: r
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Tree {
|
||||
|
|
1
gemla/src/constants/args.rs
Normal file
1
gemla/src/constants/args.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub const DIRECTORY: &str = "DIRECTORY";
|
1
gemla/src/constants/mod.rs
Normal file
1
gemla/src/constants/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod args;
|
|
@ -1,5 +1,25 @@
|
|||
mod bracket;
|
||||
mod constants;
|
||||
|
||||
#[macro_use]
|
||||
extern crate clap;
|
||||
use clap::App;
|
||||
use std::fs::metadata;
|
||||
|
||||
fn main() {
|
||||
let yaml = load_yaml!("../cli.yml");
|
||||
let matches = App::from_yaml(yaml).get_matches();
|
||||
|
||||
let directory = matches.value_of(constants::args::DIRECTORY).unwrap();
|
||||
let metadata = metadata(directory);
|
||||
|
||||
match &metadata {
|
||||
Ok(m) if m.is_dir() == true => {
|
||||
println!("{} is a valid directory!", directory);
|
||||
println!("Building tree for {}.", directory);
|
||||
bracket::run_bracket();
|
||||
},
|
||||
Ok(_) => println!("{} is not a valid directory!", directory),
|
||||
_ => println!("{} does not exist!", directory)
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue