diff options
author | Jesse Luehrs <doy@tozt.net> | 2022-01-17 23:52:15 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2022-01-17 23:52:15 -0500 |
commit | a7b16850f2437b015bcec8919586c4d4b070a35e (patch) | |
tree | 232d6eb20fcea9a763d0f1147b7c28371fba2d7b /src/main.rs | |
parent | ed9b8b345316bb8807ebbf501f19fa4684e5deba (diff) | |
download | nbsh-a7b16850f2437b015bcec8919586c4d4b070a35e.tar.gz nbsh-a7b16850f2437b015bcec8919586c4d4b070a35e.zip |
use structopt
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs index 48d2b2b..3c57bf8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,21 +26,26 @@ mod shell; use prelude::*; +#[derive(structopt::StructOpt)] +#[structopt(about = "NoteBook SHell")] +struct Opt { + #[structopt(short = "c")] + command: Option<String>, +} + async fn async_main( + opt: Opt, shell_write: Option<&async_std::fs::File>, ) -> anyhow::Result<i32> { - if std::env::args().nth(1).as_deref() == Some("-c") { - return runner::run( - std::env::args().nth(2).as_deref().unwrap(), - shell_write, - ) - .await; + if let Some(command) = opt.command { + return runner::run(&command, shell_write).await; } shell::main().await } -fn main() { +#[paw::main] +fn main(opt: Opt) { // need to do this here because the async-std executor allocates some fds, // and so in the case where we aren't being called from the main shell and // fd 3 wasn't preallocated in advance, we need to be able to tell that @@ -58,7 +63,7 @@ fn main() { None }; - match async_std::task::block_on(async_main(shell_write.as_ref())) { + match async_std::task::block_on(async_main(opt, shell_write.as_ref())) { Ok(code) => { std::process::exit(code); } |