From f5689617f46b8e9c49d1de1f236452126d074310 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Wed, 4 Aug 2021 18:03:22 -0700 Subject: [PATCH] Wrap `--help` text to terminal width (#940) --- Cargo.lock | 12 +++++++++ Cargo.toml | 5 +++- src/config.rs | 71 ++++++++++++++++++++++++++++++--------------------- 3 files changed, 58 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ad1ec19..612d2c2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -74,6 +74,7 @@ dependencies = [ "atty", "bitflags", "strsim", + "term_size", "textwrap", "unicode-width", "vec_map", @@ -558,6 +559,16 @@ dependencies = [ "tempfile", ] +[[package]] +name = "term_size" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e4129646ca0ed8f45d09b929036bafad5377103edd06e50bf574b353d2b08d9" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "termcolor" version = "1.1.2" @@ -573,6 +584,7 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" dependencies = [ + "term_size", "unicode-width", ] diff --git a/Cargo.toml b/Cargo.toml index a0c1e65..f564133 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,6 @@ members = [".", "bin/ref-type"] ansi_term = "0.12.0" atty = "0.2.0" camino = "1.0.4" -clap = "2.33.0" derivative = "2.0.0" dotenv = "0.15.0" edit-distance = "2.0.0" @@ -36,6 +35,10 @@ tempfile = "3.0.0" typed-arena = "2.0.1" unicode-width = "0.1.0" +[dependencies.clap] +version = "2.33.0" +features = ["wrap_help"] + [dependencies.ctrlc] version = "3.1.1" features = ["termination"] diff --git a/src/config.rs b/src/config.rs index e51f63f..85c8d9d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -576,17 +576,18 @@ USAGE: FLAGS: --changelog Print changelog - --choose Select one or more recipes to run using a binary. If `--chooser` is \ - not passed the chooser - defaults to the value of $JUST_CHOOSER, falling back to `fzf` + --choose Select one or more recipes to run using a binary. + If `--chooser` is not passed the chooser defaults + to the value of $JUST_CHOOSER, falling back to + `fzf` --clear-shell-args Clear shell arguments --dry-run Print what just would do without doing it --dump Print entire justfile - -e, --edit Edit justfile with editor given by $VISUAL or $EDITOR, falling back \ - to `vim` - --evaluate Evaluate and print all variables. If a variable name is given as an \ - argument, only print - that variable's value. + -e, --edit Edit justfile with editor given by $VISUAL or + $EDITOR, falling back to `vim` + --evaluate Evaluate and print all variables. If a variable + name is given as an argument, only print that + variable's value. --fmt Format and overwrite justfile --highlight Highlight echoed recipe lines in bold --init Initialize new justfile in project root @@ -594,8 +595,8 @@ FLAGS: --no-dotenv Don't load `.env` file --no-highlight Don't highlight echoed recipe lines in bold -q, --quiet Suppress all output - --shell-command Invoke with the shell used to run recipe lines and \ - backticks + --shell-command Invoke with the shell used to run recipe + lines and backticks --summary List names of available recipes -u, --unsorted Return list and summary entries in source order --unstable Enable unstable features @@ -603,34 +604,46 @@ FLAGS: -v, --verbose Use verbose output OPTIONS: - --chooser Override binary invoked by `--choose` + --chooser + Override binary invoked by `--choose` + --color - Print colorful output [default: auto] [possible values: auto, always, never] - + Print colorful output [default: auto] [possible values: auto, + always, never] -c, --command - Run an arbitrary command with the working directory, `.env`, overrides, and exports set - + Run an arbitrary command with the working directory, `.env`, + overrides, and exports set --completions - Print shell completion script for [possible values: zsh, bash, fish, \ - powershell, elvish] - + Print shell completion script for [possible values: zsh, + bash, fish, powershell, elvish] -f, --justfile Use as justfile --list-heading Print before list - --list-prefix Print before each list item - --set Override with - --shell Invoke to run recipes [default: sh] - --shell-arg ... Invoke shell with as an argument \ - [default: -cu] - -s, --show Show information about - -d, --working-directory - Use as working directory. --justfile must also be set + --list-prefix + Print before each list item + --set + Override with + + --shell + Invoke to run recipes [default: sh] + + --shell-arg ... + Invoke shell with as an argument [default: -cu] + + -s, --show + Show information about + + -d, --working-directory + Use as working directory. --justfile must also + be set ARGS: - ... Overrides and recipe(s) to run, defaulting to the first recipe in the \ - justfile"; + ... Overrides and recipe(s) to run, defaulting to the + first recipe in the justfile"; - let app = Config::app().setting(AppSettings::ColorNever); + let app = Config::app() + .setting(AppSettings::ColorNever) + .set_term_width(80); let mut buffer = Vec::new(); app.write_help(&mut buffer).unwrap(); let help = str::from_utf8(&buffer).unwrap();