feat(cli): add "--no-clear-screen" flag (#13454)

This commit adds "--no-clear-screen" flag which can be used
with "--watch" flag to disable clearing of terminal screen on
each file change.
This commit is contained in:
Zheyu Zhang 2022-02-01 00:39:39 +08:00 committed by GitHub
parent 3e566bb457
commit 5490cfed20
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 321 additions and 37 deletions

View file

@ -8,9 +8,10 @@
//! the same functions as ops available in JS runtime.
use crate::config_file::LintConfig;
use crate::file_watcher::ResolutionResult;
use crate::flags::LintFlags;
use crate::flags::{Flags, LintFlags};
use crate::fmt_errors;
use crate::fs_util::{collect_files, is_supported_ext, specifier_to_file_path};
use crate::proc_state::ProcState;
use crate::tools::fmt::run_parallelized;
use crate::{colors, file_watcher};
use deno_ast::MediaType;
@ -48,11 +49,7 @@ fn create_reporter(kind: LintReporterKind) -> Box<dyn LintReporter + Send> {
}
}
pub async fn lint(
maybe_lint_config: Option<LintConfig>,
lint_flags: LintFlags,
watch: bool,
) -> Result<(), AnyError> {
pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> {
let LintFlags {
maybe_rules_tags,
maybe_rules_include,
@ -69,6 +66,13 @@ pub async fn lint(
let mut include_files = args.clone();
let mut exclude_files = ignore.clone();
let ps = ProcState::build(flags.clone()).await?;
let maybe_lint_config = if let Some(config_file) = &ps.maybe_config_file {
config_file.to_lint_config()?
} else {
None
};
if let Some(lint_config) = maybe_lint_config.as_ref() {
if include_files.is_empty() {
include_files = lint_config
@ -166,13 +170,21 @@ pub async fn lint(
Ok(())
};
if watch {
if flags.watch.is_some() {
if args.len() == 1 && args[0].to_string_lossy() == "-" {
return Err(generic_error(
"Lint watch on standard input is not supported.",
));
}
file_watcher::watch_func(resolver, operation, "Lint").await?;
file_watcher::watch_func(
resolver,
operation,
file_watcher::PrintConfig {
job_name: "Lint".to_string(),
clear_screen: !flags.no_clear_screen,
},
)
.await?;
} else {
if args.len() == 1 && args[0].to_string_lossy() == "-" {
let reporter_lock =