summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2024-01-23 19:56:50 +0100
committerGitHub <noreply@github.com>2024-01-23 19:56:50 +0100
commitcc05dc142d1c57afd10cb08d84f99a25bd49678c (patch)
treebb825c0e1e43465bb6214b6a485d67880b68cf8d
parentd1eed9896f1dee6974816f1c16c46a1c4de0120c (diff)
chore: make deno --help more colorful (#21962)
This commit adds coloring to "--help" flag. Before: https://github.com/denoland/deno/assets/13602871/23753f95-3289-45bc-8a1e-842d0ccd92df After: https://github.com/denoland/deno/assets/13602871/91b035cc-f199-4cf4-a77c-f65b290b5e19
-rw-r--r--Cargo.lock22
-rw-r--r--cli/Cargo.toml1
-rw-r--r--cli/args/flags.rs79
3 files changed, 77 insertions, 25 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 4c3440e8c..e46621346 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -635,6 +635,27 @@ dependencies = [
]
[[package]]
+name = "color-print"
+version = "0.3.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7a858372ff14bab9b1b30ea504f2a4bc534582aee3e42ba2d41d2a7baba63d5d"
+dependencies = [
+ "color-print-proc-macro",
+]
+
+[[package]]
+name = "color-print-proc-macro"
+version = "0.3.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "57e37866456a721d0a404439a1adae37a31be4e0055590d053dfe6981e05003f"
+dependencies = [
+ "nom 7.1.3",
+ "proc-macro2",
+ "quote",
+ "syn 1.0.109",
+]
+
+[[package]]
name = "color_quant"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -955,6 +976,7 @@ dependencies = [
"clap",
"clap_complete",
"clap_complete_fig",
+ "color-print",
"console_static_text",
"dashmap",
"data-encoding",
diff --git a/cli/Cargo.toml b/cli/Cargo.toml
index 1a74469ea..a9a93a6fc 100644
--- a/cli/Cargo.toml
+++ b/cli/Cargo.toml
@@ -79,6 +79,7 @@ chrono.workspace = true
clap = { version = "=4.4.17", features = ["env", "string"] }
clap_complete = "=4.4.7"
clap_complete_fig = "=4.4.2"
+color-print = "0.3.5"
console_static_text.workspace = true
dashmap = "5.5.3"
data-encoding.workspace = true
diff --git a/cli/args/flags.rs b/cli/args/flags.rs
index 707e28256..8bb29e72d 100644
--- a/cli/args/flags.rs
+++ b/cli/args/flags.rs
@@ -1,5 +1,6 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
+use clap::builder::styling::AnsiColor;
use clap::builder::FalseyValueParser;
use clap::value_parser;
use clap::Arg;
@@ -806,61 +807,82 @@ impl Flags {
}
}
-static ENV_VARIABLES_HELP: &str = r#"ENVIRONMENT VARIABLES:
- DENO_AUTH_TOKENS A semi-colon separated list of bearer tokens and
+static ENV_VARIABLES_HELP: &str = color_print::cstr!(
+ r#"<y>Environment variables:</>
+ <g>DENO_AUTH_TOKENS</> A semi-colon separated list of bearer tokens and
hostnames to use when fetching remote modules from
private repositories
(e.g. "abcde12345@deno.land;54321edcba@github.com")
- DENO_TLS_CA_STORE Comma-separated list of order dependent certificate
+
+ <g>DENO_TLS_CA_STORE</> Comma-separated list of order dependent certificate
stores. Possible values: "system", "mozilla".
Defaults to "mozilla".
- DENO_CERT Load certificate authority from PEM encoded file
- DENO_DIR Set the cache directory
- DENO_INSTALL_ROOT Set deno install's output directory
+
+ <g>DENO_CERT</> Load certificate authority from PEM encoded file
+
+ <g>DENO_DIR</> Set the cache directory
+
+ <g>DENO_INSTALL_ROOT</> Set deno install's output directory
(defaults to $HOME/.deno/bin)
- DENO_REPL_HISTORY Set REPL history file path
+
+ <g>DENO_REPL_HISTORY</> Set REPL history file path
History file is disabled when the value is empty
(defaults to $DENO_DIR/deno_history.txt)
- DENO_NO_PACKAGE_JSON Disables auto-resolution of package.json
- DENO_NO_PROMPT Set to disable permission prompts on access
+
+ <g>DENO_NO_PACKAGE_JSON</> Disables auto-resolution of package.json
+
+ <g>DENO_NO_PROMPT</> Set to disable permission prompts on access
(alternative to passing --no-prompt on invocation)
- DENO_NO_UPDATE_CHECK Set to disable checking if a newer Deno version is
+
+ <g>DENO_NO_UPDATE_CHECK</> Set to disable checking if a newer Deno version is
available
- DENO_V8_FLAGS Set V8 command line options
- DENO_WEBGPU_TRACE Directory to use for wgpu traces
- DENO_JOBS Number of parallel workers used for the --parallel
+
+ <g>DENO_V8_FLAGS</> Set V8 command line options
+
+ <g>DENO_WEBGPU_TRACE</> Directory to use for wgpu traces
+
+ <g>DENO_JOBS</> Number of parallel workers used for the --parallel
flag with the test subcommand. Defaults to number
of available CPUs.
- HTTP_PROXY Proxy address for HTTP requests
+
+ <g>HTTP_PROXY</> Proxy address for HTTP requests
(module downloads, fetch)
- HTTPS_PROXY Proxy address for HTTPS requests
+
+ <g>HTTPS_PROXY</> Proxy address for HTTPS requests
(module downloads, fetch)
- NPM_CONFIG_REGISTRY URL to use for the npm registry.
- NO_COLOR Set to disable color
- NO_PROXY Comma-separated list of hosts which do not use a proxy
- (module downloads, fetch)"#;
+
+ <g>NPM_CONFIG_REGISTRY</> URL to use for the npm registry.
+
+ <g>NO_COLOR</> Set to disable color
+
+ <g>NO_PROXY</> Comma-separated list of hosts which do not use a proxy
+ (module downloads, fetch)"#
+);
static DENO_HELP: &str = concat!(
- "A modern JavaScript and TypeScript runtime
+ color_print::cstr!("<g>A modern JavaScript and TypeScript runtime</>"),
+ "
Docs: https://deno.land/manual@v",
env!("CARGO_PKG_VERSION"),
- "
+ color_print::cstr!(
+ "
Modules: https://deno.land/std/ https://deno.land/x/
Bugs: https://github.com/denoland/deno/issues
To start the REPL:
- deno
+ <g>deno</>
To execute a script:
- deno run https://examples.deno.land/hello-world.ts
+ <g>deno run https://examples.deno.land/hello-world.ts</>
To evaluate code in the shell:
- deno eval \"console.log(30933 + 404)\"
+ <g>deno eval \"console.log(30933 + 404)\"</>
"
+ )
);
/// Main entry point for parsing deno's command line flags.
@@ -971,7 +993,14 @@ fn clap_root() -> Command {
let mut cmd = Command::new("deno")
.bin_name("deno")
- .color(ColorChoice::Never)
+ .styles(
+ clap::builder::Styles::styled()
+ .header(AnsiColor::Yellow.on_default())
+ .usage(AnsiColor::White.on_default())
+ .literal(AnsiColor::Green.on_default())
+ .placeholder(AnsiColor::Green.on_default())
+ )
+ .color(ColorChoice::Auto)
.max_term_width(80)
.version(crate::version::deno())
.long_version(long_version)