summaryrefslogtreecommitdiff
path: root/cli/tools/doc.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2021-12-20 22:29:02 +0100
committerGitHub <noreply@github.com>2021-12-20 22:29:02 +0100
commit1eb78731eb57b1d0eb7c0ece97b2018c1724989e (patch)
treecc33e4d97733fc3bd2098ec49eed4aeb725069c8 /cli/tools/doc.rs
parent04fe5130036c4a587ae60972136d8b0efa4e5831 (diff)
refactor: Use dedicated flags structures (#13148)
Diffstat (limited to 'cli/tools/doc.rs')
-rw-r--r--cli/tools/doc.rs28
1 files changed, 17 insertions, 11 deletions
diff --git a/cli/tools/doc.rs b/cli/tools/doc.rs
index cc37df06d..2b47d7008 100644
--- a/cli/tools/doc.rs
+++ b/cli/tools/doc.rs
@@ -2,6 +2,7 @@
use crate::colors;
use crate::file_fetcher::File;
+use crate::flags::DocFlags;
use crate::flags::Flags;
use crate::get_types;
use crate::proc_state::ProcState;
@@ -92,13 +93,12 @@ impl Loader for DocLoader {
pub async fn print_docs(
flags: Flags,
- source_file: Option<String>,
- json: bool,
- maybe_filter: Option<String>,
- private: bool,
+ doc_flags: DocFlags,
) -> Result<(), AnyError> {
let ps = ProcState::build(flags.clone()).await?;
- let source_file = source_file.unwrap_or_else(|| "--builtin".to_string());
+ let source_file = doc_flags
+ .source_file
+ .unwrap_or_else(|| "--builtin".to_string());
let source_parser = deno_graph::DefaultSourceParser::new();
let parse_result = if source_file == "--builtin" {
@@ -115,7 +115,8 @@ pub async fn print_docs(
None,
)
.await;
- let doc_parser = doc::DocParser::new(graph, private, &source_parser);
+ let doc_parser =
+ doc::DocParser::new(graph, doc_flags.private, &source_parser);
doc_parser.parse_source(
&source_file_specifier,
MediaType::Dts,
@@ -153,7 +154,8 @@ pub async fn print_docs(
None,
)
.await;
- let doc_parser = doc::DocParser::new(graph, private, &source_parser);
+ let doc_parser =
+ doc::DocParser::new(graph, doc_flags.private, &source_parser);
doc_parser.parse_with_reexports(&root_specifier)
};
@@ -165,11 +167,11 @@ pub async fn print_docs(
}
};
- if json {
+ if doc_flags.json {
write_json_to_stdout(&doc_nodes)
} else {
doc_nodes.retain(|doc_node| doc_node.kind != doc::DocNodeKind::Import);
- let details = if let Some(filter) = maybe_filter {
+ let details = if let Some(filter) = doc_flags.filter {
let nodes =
doc::find_nodes_by_name_recursively(doc_nodes, filter.clone());
if nodes.is_empty() {
@@ -178,12 +180,16 @@ pub async fn print_docs(
}
format!(
"{}",
- doc::DocPrinter::new(&nodes, colors::use_color(), private)
+ doc::DocPrinter::new(&nodes, colors::use_color(), doc_flags.private)
)
} else {
format!(
"{}",
- doc::DocPrinter::new(&doc_nodes, colors::use_color(), private)
+ doc::DocPrinter::new(
+ &doc_nodes,
+ colors::use_color(),
+ doc_flags.private
+ )
)
};