gdritter repos palladio / 66d867d
Add configuration + state factory Getty Ritter 6 years ago
2 changed file(s) with 45 addition(s) and 0 deletion(s). Collapse all Expand all
1 extern crate clap;
2
3 use self::clap;
4 use constants;
5
6 pub struct Cfg {
7 file_path: Option<&'static str>,
8 }
9
10 fn palladio_args() -> Cfg {
11 let matches =
12 clap::App::new(constants::PROGRAM_NAME)
13 .version(constants::VERSION)
14 .author(constants::AUTHOR)
15
16 .arg(clap::Arg::with_name("i")
17 .short("i")
18 .long("input")
19 .value_name("FILE")
20 .help("The document to load on starting"))
21 .get_matches();
22
23 let file_path = matches.value_of("input");
24 Cfg { file_path }
25 }
11 pub mod document;
22 pub use self::document::*;
3 use failure::Error;
4 use cfg;
35
46 pub struct State {
57 pub document: Document,
68 pub save_state: SaveState,
9 }
10
11 impl State {
12 fn new(conf: cfg::Cfg) -> Result<State, Error> {
13 match conf.file_path {
14 None => State {
15 document: document.default(),
16 save_state = SaveState::Unsaved,
17 }
18 Some(path) => {
19 let mut f = File::open(path)?;
20 State {
21 document: Document::open_from_file(&mut f)?;
22 save_state: SaveState::Saved,
23 }
24 }
25 }
26 }
727 }
828
929 #[derive(Debug)]