Added command line argument parsing.

This commit is contained in:
Jacob VanDomelen 2019-05-24 19:23:50 -07:00
parent 5abe93a0dc
commit e6570cf4b7
8 changed files with 103 additions and 62 deletions

View file

@ -6,3 +6,4 @@ edition = "2018"
[dependencies] [dependencies]
uuid = { version = "0.7", features = ["serde", "v4"] } uuid = { version = "0.7", features = ["serde", "v4"] }
clap = { version = "~2.27.0", features = ["yaml"] }

9
gemla/cli.yml Normal file
View 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

View file

@ -3,11 +3,16 @@ mod state;
use uuid::Uuid; use uuid::Uuid;
// pub struct Bracket {
// tree: tree::Tree,
// directory: String
// }
fn build_tree(h: u32) -> Option<Box<tree::Tree>> { fn build_tree(h: u32) -> Option<Box<tree::Tree>> {
let mut result: Option<Box<tree::Tree>> = None; let mut result: Option<Box<tree::Tree>> = None;
if h != 0 { 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 { match &result {
Some(r) => (*r).run_simulation(), Some(r) => (*r).run_simulation(),
_ => () _ => ()
@ -25,7 +30,11 @@ pub fn run_bracket() {
println!("========================================="); println!("=========================================");
println!("Running bracket..."); println!("Running bracket...");
height += 1; 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(); tree.run_simulation();
if height == 3 {
break;
}
} }
} }

View file

@ -1,18 +1,18 @@
use uuid::Uuid; // use uuid::Uuid;
use std::fmt; // use std::fmt;
pub struct State { // pub struct State {
id: Uuid // id: Uuid
} // }
impl fmt::Display for State { // impl fmt::Display for State {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { // fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.id) // write!(f, "{}", self.id)
} // }
} // }
pub fn create(id: &Uuid) -> State { // pub fn create(id: &Uuid) -> State {
State { // State {
id: id.clone() // id: id.clone()
} // }
} // }

View file

@ -7,12 +7,12 @@ pub struct Tree {
right: Option<Box<Tree>> right: Option<Box<Tree>>
} }
pub fn concat_trees(id: Uuid, l: Option<Box<Tree>>, r: Option<Box<Tree>>) -> Box<Tree> { pub fn combine_trees(id: Uuid, l: Option<Box<Tree>>, r: Option<Box<Tree>>) -> Tree {
Box::new(Tree { Tree {
id: id, id: id,
left: l, left: l,
right: r right: r
}) }
} }
impl fmt::Display for Tree { impl fmt::Display for Tree {

View file

@ -0,0 +1 @@
pub const DIRECTORY: &str = "DIRECTORY";

View file

@ -0,0 +1 @@
pub mod args;

View file

@ -1,5 +1,25 @@
mod bracket; mod bracket;
mod constants;
#[macro_use]
extern crate clap;
use clap::App;
use std::fs::metadata;
fn main() { 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(); bracket::run_bracket();
},
Ok(_) => println!("{} is not a valid directory!", directory),
_ => println!("{} does not exist!", directory)
}
} }