diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-01-14 12:39:56 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-14 12:39:56 -0500 |
commit | 01e02d3123b494895b7b7395e81a577970987b74 (patch) | |
tree | 7658e1090b335321d8bc2489eb3955314ad8cbcd /cli/args/flags.rs | |
parent | 1712a88e6998d058c11ee213dcf15cccc563a9b0 (diff) |
refactor: create enum for `--builtin` doc flag (#17423)
Diffstat (limited to 'cli/args/flags.rs')
-rw-r--r-- | cli/args/flags.rs | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 2e99aab82..84c1d083b 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -95,10 +95,22 @@ pub struct CoverageFlags { } #[derive(Clone, Debug, Eq, PartialEq)] +pub enum DocSourceFileFlag { + Builtin, + Path(String), +} + +impl Default for DocSourceFileFlag { + fn default() -> Self { + Self::Builtin + } +} + +#[derive(Clone, Debug, Eq, PartialEq)] pub struct DocFlags { pub private: bool, pub json: bool, - pub source_file: Option<String>, + pub source_file: DocSourceFileFlag, pub filter: Option<String>, } @@ -2444,7 +2456,16 @@ fn doc_parse(flags: &mut Flags, matches: &clap::ArgMatches) { import_map_arg_parse(flags, matches); reload_arg_parse(flags, matches); - let source_file = matches.value_of("source_file").map(String::from); + let source_file = matches + .value_of("source_file") + .map(|value| { + if value == "--builtin" { + DocSourceFileFlag::Builtin + } else { + DocSourceFileFlag::Path(value.to_string()) + } + }) + .unwrap_or_default(); let private = matches.is_present("private"); let json = matches.is_present("json"); let filter = matches.value_of("filter").map(String::from); @@ -4916,7 +4937,7 @@ mod tests { r.unwrap(), Flags { subcommand: DenoSubcommand::Doc(DocFlags { - source_file: Some("script.ts".to_owned()), + source_file: DocSourceFileFlag::Path("script.ts".to_owned()), private: false, json: false, filter: None, @@ -5922,7 +5943,7 @@ mod tests { subcommand: DenoSubcommand::Doc(DocFlags { private: false, json: true, - source_file: Some("path/to/module.ts".to_string()), + source_file: DocSourceFileFlag::Path("path/to/module.ts".to_string()), filter: None, }), ..Flags::default() @@ -5941,7 +5962,7 @@ mod tests { subcommand: DenoSubcommand::Doc(DocFlags { private: false, json: false, - source_file: Some("path/to/module.ts".to_string()), + source_file: DocSourceFileFlag::Path("path/to/module.ts".to_string()), filter: Some("SomeClass.someField".to_string()), }), ..Flags::default() @@ -5955,7 +5976,7 @@ mod tests { subcommand: DenoSubcommand::Doc(DocFlags { private: false, json: false, - source_file: None, + source_file: Default::default(), filter: None, }), ..Flags::default() @@ -5969,7 +5990,7 @@ mod tests { subcommand: DenoSubcommand::Doc(DocFlags { private: false, json: false, - source_file: Some("--builtin".to_string()), + source_file: DocSourceFileFlag::Builtin, filter: Some("Deno.Listener".to_string()), }), ..Flags::default() @@ -5984,7 +6005,7 @@ mod tests { subcommand: DenoSubcommand::Doc(DocFlags { private: true, json: false, - source_file: Some("path/to/module.js".to_string()), + source_file: DocSourceFileFlag::Path("path/to/module.js".to_string()), filter: None, }), ..Flags::default() |