Make Nu bootstrap itself from main. (#3619)

We've relied on `clap` for building our cli app bootstrapping that figures out the positionals, flags, and other convenient facilities. Nu has been capable of solving this problem for quite some time. Given this and much more reasons (including the build time caused by `clap`) we start here working with our own.
This commit is contained in:
Andrés N. Robalino
2021-06-15 17:43:25 -05:00
committed by GitHub
parent ec96e85d04
commit 7c7e5112ea
16 changed files with 852 additions and 272 deletions

View File

@ -86,7 +86,7 @@ pub(crate) mod mkdir;
pub(crate) mod move_;
pub(crate) mod next;
pub(crate) mod nth;
pub(crate) mod nu;
pub mod nu;
pub(crate) mod open;
pub(crate) mod parse;
pub(crate) mod path;
@ -140,7 +140,7 @@ pub(crate) mod which_;
pub(crate) mod with_env;
pub(crate) mod wrap;
pub(crate) use autoview::Autoview;
pub use autoview::Autoview;
pub(crate) use cd::Cd;
pub(crate) use alias::Alias;

View File

@ -0,0 +1,60 @@
use nu_engine::WholeStreamCommand;
use nu_protocol::{Signature, SyntaxShape};
pub struct Command;
impl WholeStreamCommand for Command {
fn name(&self) -> &str {
"nu"
}
fn signature(&self) -> Signature {
Signature::build("nu")
.switch("stdin", "stdin", None)
.switch("skip-plugins", "do not load plugins", None)
.switch("no-history", "don't save history", None)
.named("commands", SyntaxShape::String, "Nu commands", Some('c'))
.named(
"testbin",
SyntaxShape::String,
"BIN: echo_env, cococo, iecho, fail, nonu, chop, repeater, meow",
None,
)
.named("develop", SyntaxShape::String, "trace mode", None)
.named("debug", SyntaxShape::String, "debug mode", None)
.named(
"loglevel",
SyntaxShape::String,
"LEVEL: error, warn, info, debug, trace",
Some('l'),
)
.named(
"config-file",
SyntaxShape::FilePath,
"custom configuration source file",
None,
)
.optional("script", SyntaxShape::FilePath, "The Nu script to run")
.rest(SyntaxShape::String, "Left overs...")
}
fn usage(&self) -> &str {
"Nu"
}
}
pub fn testbins() -> Vec<String> {
vec![
"echo_env", "cococo", "iecho", "fail", "nonu", "chop", "repeater", "meow",
]
.into_iter()
.map(String::from)
.collect()
}
pub fn loglevels() -> Vec<String> {
vec!["error", "warn", "info", "debug", "trace"]
.into_iter()
.map(String::from)
.collect()
}

View File

@ -1,3 +1,6 @@
pub mod command;
mod plugin;
pub use command::Command as Nu;
pub use command::{loglevels, testbins};
pub use plugin::SubCommand as NuPlugin;

View File

@ -52,7 +52,7 @@ pub fn source(args: CommandArgs) -> Result<ActionStream, ShellError> {
let result = script::run_script_standalone(contents, true, &ctx, false);
if let Err(err) = result {
ctx.error(err.into());
ctx.error(err);
}
Ok(ActionStream::empty())
}