Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrap_help can fail to wrap at the correct point #5022

Closed
2 tasks done
Xophmeister opened this issue Jul 19, 2023 · 1 comment · Fixed by #5023
Closed
2 tasks done

wrap_help can fail to wrap at the correct point #5022

Xophmeister opened this issue Jul 19, 2023 · 1 comment · Fixed by #5023
Labels
C-bug Category: Updating dependencies

Comments

@Xophmeister
Copy link

Please complete the following tasks

Rust Version

rustc 1.70.0 (90c541806 2023-05-31) (built from a source tarball)

Clap Version

4.3.16

Minimal reproducible code

use clap::{Parser, ValueEnum};

#[derive(Debug, Parser)]
struct Cli {
    #[arg(short)]
    foo: Foo,
}

#[derive(Clone, Debug, ValueEnum)]
enum Foo {
    /// Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
    /// ut labore et dolore magna aliqua. Sed vulputate mi sit amet mauris commodo quis imperdiet
    /// massa.
    Foo,
}

fn main() {
    let cli = Cli::parse();
    println!("{cli:?}");
}

Steps to reproduce the bug with the above code

Set your terminal to 90 columns, for example, then:

cargo run -- --help

Actual Behaviour

Output (manually hard-wrapped for sake of demonstration):

Usage: example -f <FOO>

Options:
  -f <FOO>
          Possible values:
          - foo: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod t
empor
            incididunt ut labore et dolore magna aliqua. Sed vulputate mi sit amet mauris
            commodo quis imperdiet massa

  -h, --help
          Print help (see a summary with '-h')

Expected Behaviour

Output:

Usage: example -f <FOO>

Options:
  -f <FOO>
          Possible values:
          - foo: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
            tempor incididunt ut labore et dolore magna aliqua. Sed vulputate mi sit amet
            mauris commodo quis imperdiet massa

  -h, --help
          Print help (see a summary with '-h')

Additional Context

Tested in Zsh 5.8.1 and Bash 5.1.16, both running inside and outside Tmux 3.2a.

Debug Output

[clap_builder::builder::command]Command::_do_parse
[clap_builder::builder::command]Command::_build: name="example"
[clap_builder::builder::command]Command::_propagate:example
[clap_builder::builder::command]Command::_check_help_and_version:example expand_help_tree=false
[clap_builder::builder::command]Command::long_help_exists
[clap_builder::builder::command]Command::_check_help_and_version: Building default --help
[clap_builder::builder::command]Command::_propagate_global_args:example
[clap_builder::builder::debug_asserts]Command::_debug_asserts
[clap_builder::builder::debug_asserts]Arg::_debug_asserts:foo
[clap_builder::builder::debug_asserts]Arg::_debug_asserts:help
[clap_builder::builder::debug_asserts]Command::_verify_positionals
[clap_builder::parser::parser]Parser::get_matches_with
[clap_builder::parser::parser]Parser::get_matches_with: Begin parsing '"--help"'
[clap_builder::parser::parser]Parser::possible_subcommand: arg=Ok("--help")
[clap_builder::parser::parser]Parser::get_matches_with: sc=None
[clap_builder::parser::parser]Parser::parse_long_arg
[clap_builder::parser::parser]Parser::parse_long_arg: Does it contain '='...
[clap_builder::parser::parser]Parser::parse_long_arg: Found valid arg or flag '--help'
[clap_builder::parser::parser]Parser::parse_long_arg("help"): Presence validated
[clap_builder::parser::parser]Parser::react action=Help, identifier=Some(Long), source=CommandLine
[clap_builder::parser::parser]Help: use_long=true
[clap_builder::builder::command]Command::long_help_exists: true
[clap_builder::builder::command]Command::write_help_err: example, use_long=true
[clap_builder::builder::command]Command::long_help_exists: true
[  clap_builder::output::help]write_help
[clap_builder::output::help_template]HelpTemplate::new cmd=example, use_long=true
[clap_builder::output::help_template]should_show_arg: use_long=true, arg=foo
[clap_builder::output::help_template]HelpTemplate::write_templated_help
[clap_builder::output::help_template]HelpTemplate::write_before_help
[ clap_builder::output::usage]Usage::create_usage_no_title
[ clap_builder::output::usage]Usage::create_help_usage; incl_reqs=true
[ clap_builder::output::usage]Usage::needs_options_tag
[ clap_builder::output::usage]Usage::needs_options_tag:iter: f=foo
[ clap_builder::output::usage]Usage::needs_options_tag:iter Option is required
[ clap_builder::output::usage]Usage::needs_options_tag:iter: f=help
[ clap_builder::output::usage]Usage::needs_options_tag:iter Option is built-in
[ clap_builder::output::usage]Usage::needs_options_tag: [OPTIONS] not required
[ clap_builder::output::usage]Usage::get_args: incls=[]
[ clap_builder::output::usage]Usage::get_args: unrolled_reqs=["foo"]
[ clap_builder::output::usage]Usage::get_args: ret_val=[StyledStr("\u{1b}[1m-f\u{1b}[0m <FOO>")]
[ clap_builder::output::usage]Usage::create_help_usage: usage=example -f <FOO>
[clap_builder::output::help_template]HelpTemplate::write_all_args
[clap_builder::output::help_template]should_show_arg: use_long=true, arg=foo
[clap_builder::output::help_template]should_show_arg: use_long=true, arg=help
[clap_builder::output::help_template]HelpTemplate::write_args Options
[clap_builder::output::help_template]should_show_arg: use_long=true, arg=foo
[clap_builder::output::help_template]HelpTemplate::write_args: arg="foo" longest=8
[clap_builder::output::help_template]should_show_arg: use_long=true, arg=help
[clap_builder::output::help_template]HelpTemplate::write_args: arg="help" longest=8
[clap_builder::output::help_template]should_show_arg: use_long=true, arg=foo
[clap_builder::output::help_template]HelpTemplate::spec_vals: a=-f <FOO>
[clap_builder::output::help_template]HelpTemplate::spec_vals: a=-f <FOO>
[clap_builder::output::help_template]HelpTemplate::short
[clap_builder::output::help_template]HelpTemplate::long
[clap_builder::output::help_template]HelpTemplate::align_to_about: arg=foo, next_line_help=true, longest=8
[clap_builder::output::help_template]HelpTemplate::align_to_about: printing long help so skip alignment
[clap_builder::output::help_template]HelpTemplate::help
[clap_builder::output::help_template]HelpTemplate::help: Next Line...true
[clap_builder::output::help_template]HelpTemplate::help: help_width=10, spaces=0, avail=80
[clap_builder::output::help_template]HelpTemplate::help: Found possible vals...[PossibleValue { name: "foo", help: Some(StyledStr("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Sed vulputate mi sit amet mauris commodo quis imperdiet massa")), aliases: [], hide: false }]
[clap_builder::output::help_template]HelpTemplate::help: Possible Value help
[clap_builder::output::help_template]HelpTemplate::spec_vals: a=--help
[clap_builder::output::help_template]HelpTemplate::short
[clap_builder::output::help_template]HelpTemplate::long
[clap_builder::output::help_template]HelpTemplate::align_to_about: arg=help, next_line_help=true, longest=8
[clap_builder::output::help_template]HelpTemplate::align_to_about: printing long help so skip alignment
[clap_builder::output::help_template]HelpTemplate::help
[clap_builder::output::help_template]HelpTemplate::help: Next Line...true
[clap_builder::output::help_template]HelpTemplate::help: help_width=10, spaces=36, avail=80
[clap_builder::output::help_template]HelpTemplate::write_after_help
[clap_builder::builder::command]Command::color: Color setting...
[clap_builder::builder::command]Auto
[clap_builder::builder::command]Command::color: Color setting...
[clap_builder::builder::command]Auto
@Xophmeister Xophmeister added the C-bug Category: Updating dependencies label Jul 19, 2023
Xophmeister added a commit to tweag/topiary that referenced this issue Jul 19, 2023
@epage
Copy link
Member

epage commented Jul 19, 2023

For a full reproduction case:

#!/usr/bin/env nargo
/*!
```cargo
[dependencies]
clap = { version = "4", features = ["derive", "wrap_help"] }
```
*/

use clap::{Parser, ValueEnum};

#[derive(Debug, Parser)]
struct Cli {
    #[arg(short)]
    foo: Foo,
}

#[derive(Clone, Debug, ValueEnum)]
enum Foo {
    /// Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
    /// ut labore et dolore magna aliqua. Sed vulputate mi sit amet mauris commodo quis imperdiet
    /// massa.
    Foo,
}

fn main() {
    let cli = Cli::parse();
    println!("{cli:?}");
}

(nargo is just a shell script around cargo that enables the nightly feature for this)

epage added a commit to epage/clap that referenced this issue Jul 19, 2023
We weren't taking the name into account when determining the wrap width.

Fixes clap-rs#5022
epage added a commit to epage/clap that referenced this issue Jul 19, 2023
We weren't taking the name into account when determining the wrap width.

Fixes clap-rs#5022
Xophmeister added a commit to tweag/topiary that referenced this issue Aug 14, 2023
* Add env feature to clap and cargo update

* Dead Code: WIP CLI changes

* Dead Code: CLI feature parity

Although see clap-rs/clap#5020

* Note about not (yet) using infer_subcommands

See clap-rs/clap#5021

* Use clap/wrap_help

Although see clap-rs/clap#5022

* WIP: Strip out previous CLI argument parser setup

[skip ci]

* WIP: Normalise arguments for caller

[skip ci]

* Don't check for file-ness in the CLI argument parser

* File and directory canonicalisation for the argument parser

* Expose CLI types so they can be used downstream
Xophmeister added a commit to tweag/topiary that referenced this issue Aug 14, 2023
* Add env feature to clap and cargo update

* Dead Code: WIP CLI changes

* Dead Code: CLI feature parity

Although see clap-rs/clap#5020

* Note about not (yet) using infer_subcommands

See clap-rs/clap#5021

* Use clap/wrap_help

Although see clap-rs/clap#5022

* WIP: Strip out previous CLI argument parser setup

[skip ci]

* WIP: Normalise arguments for caller

[skip ci]

* Don't check for file-ness in the CLI argument parser

* File and directory canonicalisation for the argument parser

* Expose CLI types so they can be used downstream
Xophmeister added a commit to tweag/topiary that referenced this issue Aug 17, 2023
Note that clap doesn't support (--foo [--bar] | --quux) groups very
cleanly; it was a bit of a hack to get this to work, with the result
being the error text being a bit off when an illegal combination is
attempted. I've attempted to compensate for this by making the long help
text quite explicit.

Also updated clap, which contains the fix for clap-rs/clap#5022
Xophmeister added a commit to tweag/topiary that referenced this issue Aug 18, 2023
* Note about not using infer_subcommands

* --tolerate-parsing-errors doesn't make sense for visualisation

* Separate out input source types so we can create a unified interface

* Fallback to the given output path if canonicalisation fails

Resolves #588

* We're going to need an InputFile, too

* WIP: InputFile type

* Correct blunder regarding --query

Note that clap doesn't support (--foo [--bar] | --quux) groups very
cleanly; it was a bit of a hack to get this to work, with the result
being the error text being a bit off when an illegal combination is
attempted. I've attempted to compensate for this by making the long help
text quite explicit.

Also updated clap, which contains the fix for clap-rs/clap#5022

* Missed change to README

* Add note RE clap-rs/clap#4707 workaround

* Machinery to unify inputs + downstream use to reimplement visualisation

* Don't flatten-away errors

* Don't open the input file until we need to read from it

* Into InputFrom should be from &AtLeastOneInput

* Add logging

* Moar logging!1!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Updating dependencies
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants