feat(tree): Auto-detect '--charset' mode

This commit is contained in:
Ed Page 2024-01-19 16:44:37 -06:00
parent 403fbe2b49
commit 6ca939863f
8 changed files with 61 additions and 41 deletions

10
Cargo.lock generated
View File

@ -336,6 +336,7 @@ dependencies = [
"shell-escape",
"snapbox",
"supports-hyperlinks",
"supports-unicode",
"tar",
"tempfile",
"time",
@ -3243,6 +3244,15 @@ version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c0a1e5168041f5f3ff68ff7d95dcb9c8749df29f6e7e89ada40dd4c9de404ee"
[[package]]
name = "supports-unicode"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f850c19edd184a205e883199a261ed44471c81e39bd95b1357f5febbef00e77a"
dependencies = [
"is-terminal",
]
[[package]]
name = "syn"
version = "1.0.109"

View File

@ -204,6 +204,7 @@ unicase.workspace = true
unicode-width.workspace = true
url.workspace = true
walkdir.workspace = true
supports-unicode = "2.1.0"
[target.'cfg(target_has_atomic = "64")'.dependencies]
tracing-chrome.workspace = true

View File

@ -7,6 +7,7 @@ use cargo::ops::Packages;
use cargo::util::print_available_packages;
use cargo::util::CargoResult;
use std::collections::HashSet;
use std::io::IsTerminal as _;
use std::str::FromStr;
pub fn cli() -> Command {
@ -69,8 +70,7 @@ pub fn cli() -> Command {
.arg(
opt("charset", "Character set to use in output")
.value_name("CHARSET")
.value_parser(["utf8", "ascii"])
.default_value("utf8"),
.value_parser(["utf8", "ascii"]),
)
.arg(
opt("format", "Format string used for printing dependencies")
@ -181,8 +181,18 @@ subtree of the package given to -p.\n\
print_available_packages(&ws)?;
}
let charset = tree::Charset::from_str(args.get_one::<String>("charset").unwrap())
let charset = args.get_one::<String>("charset");
let charset = charset
.map(|c| tree::Charset::from_str(c))
.transpose()
.map_err(|e| anyhow::anyhow!("{}", e))?;
let charset = charset.unwrap_or_else(|| {
if supports_unicode::supports_unicode() || !std::io::stdout().is_terminal() {
tree::Charset::Utf8
} else {
tree::Charset::Ascii
}
});
let opts = tree::TreeOptions {
cli_features: args.cli_features()?,
packages,

View File

@ -150,7 +150,7 @@ The default is the host platform. Use the value `all` to include *all* targets.
{{#option "`--charset` _charset_" }}
Chooses the character set to use for the tree. Valid values are "utf8" or
"ascii". Default is "utf8".
"ascii". When unspecified, cargo will auto-select a value.
{{/option}}
{{#option "`-f` _format_" "`--format` _format_" }}

View File

@ -141,7 +141,8 @@ OPTIONS
Tree Formatting Options
--charset charset
Chooses the character set to use for the tree. Valid values are
“utf8” or “ascii”. Default is “utf8”.
“utf8” or “ascii”. When unspecified, cargo will auto-select
a value.
-f format, --format format
Set the format string for each package. The default is “{p}”.

View File

@ -146,7 +146,7 @@ The default is the host platform. Use the value <code>all</code> to include <em>
<dt class="option-term" id="option-cargo-tree---charset"><a class="option-anchor" href="#option-cargo-tree---charset"></a><code>--charset</code> <em>charset</em></dt>
<dd class="option-desc">Chooses the character set to use for the tree. Valid values are “utf8” or
“ascii”. Default is “utf8”.</dd>
“ascii”. When unspecified, cargo will auto-select a value.</dd>
<dt class="option-term" id="option-cargo-tree--f"><a class="option-anchor" href="#option-cargo-tree--f"></a><code>-f</code> <em>format</em></dt>

View File

@ -175,7 +175,7 @@ The default is the host platform. Use the value \fBall\fR to include \fIall\fR t
\fB\-\-charset\fR \fIcharset\fR
.RS 4
Chooses the character set to use for the tree. Valid values are \[lq]utf8\[rq] or
\[lq]ascii\[rq]\&. Default is \[lq]utf8\[rq]\&.
\[lq]ascii\[rq]\&. When unspecified, cargo will auto\-select a value.
.RE
.sp
\fB\-f\fR \fIformat\fR,

View File

@ -1,4 +1,4 @@
<svg width="860px" height="848px" xmlns="http://www.w3.org/2000/svg">
<svg width="860px" height="830px" xmlns="http://www.w3.org/2000/svg">
<style>
.fg { fill: #AAAAAA }
.bg { background: #000000 }
@ -47,69 +47,67 @@
</tspan>
<tspan x="10px" y="262px"><tspan> </tspan><tspan class="fg-cyan bold">-d</tspan><tspan>, </tspan><tspan class="fg-cyan bold">--duplicates</tspan><tspan> Show only dependencies which come in multiple versions (implies -i)</tspan>
</tspan>
<tspan x="10px" y="280px"><tspan> </tspan><tspan class="fg-cyan bold">--charset</tspan><tspan class="fg-cyan"> </tspan><tspan class="fg-cyan">&lt;CHARSET&gt;</tspan><tspan> Character set to use in output [default: utf8] [possible values: utf8,</tspan>
<tspan x="10px" y="280px"><tspan> </tspan><tspan class="fg-cyan bold">--charset</tspan><tspan class="fg-cyan"> </tspan><tspan class="fg-cyan">&lt;CHARSET&gt;</tspan><tspan> Character set to use in output [possible values: utf8, ascii]</tspan>
</tspan>
<tspan x="10px" y="298px"><tspan> ascii]</tspan>
<tspan x="10px" y="298px"><tspan> </tspan><tspan class="fg-cyan bold">-f</tspan><tspan>, </tspan><tspan class="fg-cyan bold">--format</tspan><tspan class="fg-cyan"> </tspan><tspan class="fg-cyan">&lt;FORMAT&gt;</tspan><tspan> Format string used for printing dependencies [default: {p}]</tspan>
</tspan>
<tspan x="10px" y="316px"><tspan> </tspan><tspan class="fg-cyan bold">-f</tspan><tspan>, </tspan><tspan class="fg-cyan bold">--format</tspan><tspan class="fg-cyan"> </tspan><tspan class="fg-cyan">&lt;FORMAT&gt;</tspan><tspan> Format string used for printing dependencies [default: {p}]</tspan>
<tspan x="10px" y="316px"><tspan> </tspan><tspan class="fg-cyan bold">-v</tspan><tspan>, </tspan><tspan class="fg-cyan bold">--verbose</tspan><tspan class="fg-cyan">...</tspan><tspan> Use verbose output (-vv very verbose/build.rs output)</tspan>
</tspan>
<tspan x="10px" y="334px"><tspan> </tspan><tspan class="fg-cyan bold">-v</tspan><tspan>, </tspan><tspan class="fg-cyan bold">--verbose</tspan><tspan class="fg-cyan">...</tspan><tspan> Use verbose output (-vv very verbose/build.rs output)</tspan>
<tspan x="10px" y="334px"><tspan> </tspan><tspan class="fg-cyan bold">-q</tspan><tspan>, </tspan><tspan class="fg-cyan bold">--quiet</tspan><tspan> Do not print cargo log messages</tspan>
</tspan>
<tspan x="10px" y="352px"><tspan> </tspan><tspan class="fg-cyan bold">-q</tspan><tspan>, </tspan><tspan class="fg-cyan bold">--quiet</tspan><tspan> Do not print cargo log messages</tspan>
<tspan x="10px" y="352px"><tspan> </tspan><tspan class="fg-cyan bold">--color</tspan><tspan class="fg-cyan"> </tspan><tspan class="fg-cyan">&lt;WHEN&gt;</tspan><tspan> Coloring: auto, always, never</tspan>
</tspan>
<tspan x="10px" y="370px"><tspan> </tspan><tspan class="fg-cyan bold">--color</tspan><tspan class="fg-cyan"> </tspan><tspan class="fg-cyan">&lt;WHEN&gt;</tspan><tspan> Coloring: auto, always, never</tspan>
<tspan x="10px" y="370px"><tspan> </tspan><tspan class="fg-cyan bold">--config</tspan><tspan class="fg-cyan"> </tspan><tspan class="fg-cyan">&lt;KEY=VALUE&gt;</tspan><tspan> Override a configuration value</tspan>
</tspan>
<tspan x="10px" y="388px"><tspan> </tspan><tspan class="fg-cyan bold">--config</tspan><tspan class="fg-cyan"> </tspan><tspan class="fg-cyan">&lt;KEY=VALUE&gt;</tspan><tspan> Override a configuration value</tspan>
<tspan x="10px" y="388px"><tspan> </tspan><tspan class="fg-cyan bold">-Z</tspan><tspan class="fg-cyan"> </tspan><tspan class="fg-cyan">&lt;FLAG&gt;</tspan><tspan> Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details</tspan>
</tspan>
<tspan x="10px" y="406px"><tspan> </tspan><tspan class="fg-cyan bold">-Z</tspan><tspan class="fg-cyan"> </tspan><tspan class="fg-cyan">&lt;FLAG&gt;</tspan><tspan> Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details</tspan>
<tspan x="10px" y="406px"><tspan> </tspan><tspan class="fg-cyan bold">-h</tspan><tspan>, </tspan><tspan class="fg-cyan bold">--help</tspan><tspan> Print help</tspan>
</tspan>
<tspan x="10px" y="424px"><tspan> </tspan><tspan class="fg-cyan bold">-h</tspan><tspan>, </tspan><tspan class="fg-cyan bold">--help</tspan><tspan> Print help</tspan>
<tspan x="10px" y="424px">
</tspan>
<tspan x="10px" y="442px">
<tspan x="10px" y="442px"><tspan class="fg-green bold">Package Selection:</tspan>
</tspan>
<tspan x="10px" y="460px"><tspan class="fg-green bold">Package Selection:</tspan>
<tspan x="10px" y="460px"><tspan> </tspan><tspan class="fg-cyan bold">-p</tspan><tspan>, </tspan><tspan class="fg-cyan bold">--package</tspan><tspan class="fg-cyan"> [</tspan><tspan class="fg-cyan">&lt;SPEC&gt;</tspan><tspan class="fg-cyan">]</tspan><tspan> Package to be used as the root of the tree</tspan>
</tspan>
<tspan x="10px" y="478px"><tspan> </tspan><tspan class="fg-cyan bold">-p</tspan><tspan>, </tspan><tspan class="fg-cyan bold">--package</tspan><tspan class="fg-cyan"> [</tspan><tspan class="fg-cyan">&lt;SPEC&gt;</tspan><tspan class="fg-cyan">]</tspan><tspan> Package to be used as the root of the tree</tspan>
<tspan x="10px" y="478px"><tspan> </tspan><tspan class="fg-cyan bold">--workspace</tspan><tspan> Display the tree for all packages in the workspace</tspan>
</tspan>
<tspan x="10px" y="496px"><tspan> </tspan><tspan class="fg-cyan bold">--workspace</tspan><tspan> Display the tree for all packages in the workspace</tspan>
<tspan x="10px" y="496px"><tspan> </tspan><tspan class="fg-cyan bold">--exclude</tspan><tspan class="fg-cyan"> </tspan><tspan class="fg-cyan">&lt;SPEC&gt;</tspan><tspan> Exclude specific workspace members</tspan>
</tspan>
<tspan x="10px" y="514px"><tspan> </tspan><tspan class="fg-cyan bold">--exclude</tspan><tspan class="fg-cyan"> </tspan><tspan class="fg-cyan">&lt;SPEC&gt;</tspan><tspan> Exclude specific workspace members</tspan>
<tspan x="10px" y="514px">
</tspan>
<tspan x="10px" y="532px">
<tspan x="10px" y="532px"><tspan class="fg-green bold">Feature Selection:</tspan>
</tspan>
<tspan x="10px" y="550px"><tspan class="fg-green bold">Feature Selection:</tspan>
<tspan x="10px" y="550px"><tspan> </tspan><tspan class="fg-cyan bold">-F</tspan><tspan>, </tspan><tspan class="fg-cyan bold">--features</tspan><tspan class="fg-cyan"> </tspan><tspan class="fg-cyan">&lt;FEATURES&gt;</tspan><tspan> Space or comma separated list of features to activate</tspan>
</tspan>
<tspan x="10px" y="568px"><tspan> </tspan><tspan class="fg-cyan bold">-F</tspan><tspan>, </tspan><tspan class="fg-cyan bold">--features</tspan><tspan class="fg-cyan"> </tspan><tspan class="fg-cyan">&lt;FEATURES&gt;</tspan><tspan> Space or comma separated list of features to activate</tspan>
<tspan x="10px" y="568px"><tspan> </tspan><tspan class="fg-cyan bold">--all-features</tspan><tspan> Activate all available features</tspan>
</tspan>
<tspan x="10px" y="586px"><tspan> </tspan><tspan class="fg-cyan bold">--all-features</tspan><tspan> Activate all available features</tspan>
<tspan x="10px" y="586px"><tspan> </tspan><tspan class="fg-cyan bold">--no-default-features</tspan><tspan> Do not activate the `default` feature</tspan>
</tspan>
<tspan x="10px" y="604px"><tspan> </tspan><tspan class="fg-cyan bold">--no-default-features</tspan><tspan> Do not activate the `default` feature</tspan>
<tspan x="10px" y="604px">
</tspan>
<tspan x="10px" y="622px">
<tspan x="10px" y="622px"><tspan class="fg-green bold">Compilation Options:</tspan>
</tspan>
<tspan x="10px" y="640px"><tspan class="fg-green bold">Compilation Options:</tspan>
<tspan x="10px" y="640px"><tspan> </tspan><tspan class="fg-cyan bold">--target</tspan><tspan class="fg-cyan"> [</tspan><tspan class="fg-cyan">&lt;TRIPLE&gt;</tspan><tspan class="fg-cyan">]</tspan><tspan> Filter dependencies matching the given target-triple (default host</tspan>
</tspan>
<tspan x="10px" y="658px"><tspan> </tspan><tspan class="fg-cyan bold">--target</tspan><tspan class="fg-cyan"> [</tspan><tspan class="fg-cyan">&lt;TRIPLE&gt;</tspan><tspan class="fg-cyan">]</tspan><tspan> Filter dependencies matching the given target-triple (default host</tspan>
<tspan x="10px" y="658px"><tspan> platform). Pass `all` to include all targets.</tspan>
</tspan>
<tspan x="10px" y="676px"><tspan> platform). Pass `all` to include all targets.</tspan>
<tspan x="10px" y="676px">
</tspan>
<tspan x="10px" y="694px">
<tspan x="10px" y="694px"><tspan class="fg-green bold">Manifest Options:</tspan>
</tspan>
<tspan x="10px" y="712px"><tspan class="fg-green bold">Manifest Options:</tspan>
<tspan x="10px" y="712px"><tspan> </tspan><tspan class="fg-cyan bold">--manifest-path</tspan><tspan class="fg-cyan"> </tspan><tspan class="fg-cyan">&lt;PATH&gt;</tspan><tspan> Path to Cargo.toml</tspan>
</tspan>
<tspan x="10px" y="730px"><tspan> </tspan><tspan class="fg-cyan bold">--manifest-path</tspan><tspan class="fg-cyan"> </tspan><tspan class="fg-cyan">&lt;PATH&gt;</tspan><tspan> Path to Cargo.toml</tspan>
<tspan x="10px" y="730px"><tspan> </tspan><tspan class="fg-cyan bold">--frozen</tspan><tspan> Require Cargo.lock and cache are up to date</tspan>
</tspan>
<tspan x="10px" y="748px"><tspan> </tspan><tspan class="fg-cyan bold">--frozen</tspan><tspan> Require Cargo.lock and cache are up to date</tspan>
<tspan x="10px" y="748px"><tspan> </tspan><tspan class="fg-cyan bold">--locked</tspan><tspan> Require Cargo.lock is up to date</tspan>
</tspan>
<tspan x="10px" y="766px"><tspan> </tspan><tspan class="fg-cyan bold">--locked</tspan><tspan> Require Cargo.lock is up to date</tspan>
<tspan x="10px" y="766px"><tspan> </tspan><tspan class="fg-cyan bold">--offline</tspan><tspan> Run without accessing the network</tspan>
</tspan>
<tspan x="10px" y="784px"><tspan> </tspan><tspan class="fg-cyan bold">--offline</tspan><tspan> Run without accessing the network</tspan>
<tspan x="10px" y="784px">
</tspan>
<tspan x="10px" y="802px">
<tspan x="10px" y="802px"><tspan>Run `</tspan><tspan class="fg-cyan bold">cargo help tree</tspan><tspan class="bold">` for more detailed information.</tspan>
</tspan>
<tspan x="10px" y="820px"><tspan>Run `</tspan><tspan class="fg-cyan bold">cargo help tree</tspan><tspan class="bold">` for more detailed information.</tspan>
</tspan>
<tspan x="10px" y="838px">
<tspan x="10px" y="820px">
</tspan>
</text>

Before

Width:  |  Height:  |  Size: 8.4 KiB

After

Width:  |  Height:  |  Size: 8.3 KiB