1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00

Flags clean up: DenoFlags::from (#2068)

This commit is contained in:
Bartek Iwańczuk 2019-04-07 20:58:16 +02:00 committed by Ryan Dahl
parent 3995473925
commit 86aee7f137

View file

@ -26,20 +26,10 @@ pub struct DenoFlags {
pub fmt: bool, pub fmt: bool,
} }
/// Checks provided arguments for known options and sets appropriate Deno flags impl<'a> From<ArgMatches<'a>> for DenoFlags {
/// for them. Unknown options are returned for further use. fn from(matches: ArgMatches) -> DenoFlags {
/// Note: let mut flags = DenoFlags::default();
///
/// 1. This assumes that privileged flags do not accept parameters deno --foo bar.
/// This assumption is currently valid. But if it were to change in the future,
/// this parsing technique would need to be modified. I think we want to keep the
/// privileged flags minimal - so having this restriction is maybe a good thing.
///
/// 2. Misspelled flags will be forwarded to user code - e.g. --allow-ne would
/// not cause an error. I also think this is ok because missing any of the
/// privileged flags is not destructive. Userland flag parsing would catch these
/// errors.
fn set_recognized_flags(matches: ArgMatches, flags: &mut DenoFlags) {
if matches.is_present("log-debug") { if matches.is_present("log-debug") {
flags.log_debug = true; flags.log_debug = true;
} }
@ -87,6 +77,9 @@ fn set_recognized_flags(matches: ArgMatches, flags: &mut DenoFlags) {
if matches.is_present("fmt") { if matches.is_present("fmt") {
flags.fmt = true; flags.fmt = true;
} }
flags
}
} }
#[cfg_attr(feature = "cargo-clippy", allow(stutter))] #[cfg_attr(feature = "cargo-clippy", allow(stutter))]
@ -242,8 +235,7 @@ pub fn set_flags(
v8_set_flags(v8_flags); v8_set_flags(v8_flags);
} }
let mut flags = DenoFlags::default(); let flags = DenoFlags::from(matches);
set_recognized_flags(matches, &mut flags);
Ok((flags, rest)) Ok((flags, rest))
} }