Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better cli #27

Merged
merged 1 commit into from
Jul 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ use crate::{error::CliError, generator::voiceflow::*, parser::ConversationBuilde
use argparse::{Cli, Command, Flag, FlagParse};
use log::{debug, info};

const HELP_MSG: &'static str = r#"
fdc - the flowdown compiler

USAGE: fdc [INPUT]

OPTIONS:
-h, --help print this help message
-p, --pretty format output file nicely
-o, --output <FILE> specify file to output to
"#;

fn main() {
env_logger::builder().format_timestamp(None).init();

Expand All @@ -22,6 +33,7 @@ fn main() {
desc: "",
handler: handle_compile,
flags: vec![
Flag::new('h').long("help"),
Flag::new('o')
.long("output")
.desc("file to output to")
Expand All @@ -34,15 +46,23 @@ fn main() {
..Default::default()
};

use std::io::*;
let args = std::env::args().collect();
cli.run(&args).unwrap();
if let Err(boxed) = cli.run(&args) {
write!(stderr(), "{}", boxed).unwrap();
}
}

fn handle_compile(flagparse: FlagParse) -> Result<(), Box<dyn std::error::Error>> {
use std::fs::*;
use std::io::*;
use std::path::*;

if flagparse.get_flag('h') {
println!("{}", HELP_MSG);
return Ok(());
}

let output_file = flagparse.get_flag_value::<String>('o');

debug!("{:?}", flagparse.args);
Expand Down