sd: man page rendering is broken, resulting in broken examples

broken examples on man page as rendered in bash on macOS:

Regex use. Let's trim some trailing whitespace
       $ echo 'lorem ipsum 23   ' | sd '' ''
       lorem ipsum 23

Indexed capture groups
       $ echo 'cargo +nightly watch' | sd '(0(24
       cmd: cargo, channel: nightly, subcmd: watch

Named capture groups
       $ echo "123.45" | sd '(?P<dollars>+).(?P<cents>+)' '$dollars dollars and $cents cents'
       123 dollars and 45 cents

Same examples from README:

  1. Basic regex use - let’s trim some trailing whitespace
> echo 'lorem ipsum 23   ' | sd '\s+$' ''
lorem ipsum 23
  1. Capture groups

Indexed capture groups:

> echo 'cargo +nightly watch' | sd '(\w+)\s+\+(\w+)\s+(\w+)' 'cmd: > $1, channel: $2, subcmd: $3'
cmd: cargo, channel: nightly, subcmd: watch

Named capture groups:

> echo "123.45" | sd '(?P<dollars>\d+)\.(?P<cents>\d+)' '$dollars > dollars and $cents cents'
123 dollars and 45 cents

About this issue

  • Original URL
  • State: closed
  • Created 9 months ago
  • Comments: 15 (5 by maintainers)

Most upvoted comments

You already include!ed ../../src/cli.rs, that’s one thing. But clap reads the current Cargo.toml, which has the name xtask, so you gotta also cmd.name("sd").

Reading (the top level) Cargo.toml is required to get the version.

(Sorry my hand went faster than brain)

Since this project already uses clap for the CLI arg parsing it would make sense to drop both the custom completions and the man page code from the repository and have it generated at build time by clap_complete and clap_mangen respectively. These crates can be triggered just from build.rs so they don’t have to be baked into the final binary but can generate fresh up to date completions and man pages at build time so they never get out of sync. This is probably something I could contribute if the project is willing to accept it. Additionally if the project is interested I could add autotools plumbing so that all the unix-y bits like completions and man pages would get installed to the correct places if installed with ./configure && make install. This would not hinder installation of the bare binary with cargo install, but for those that chose to use the autotools build method would result in not just the binary but the supporting files as well being installed to the correct places. Far an example of this being done (completions, man pages, & autotools install) you can see my git-warp-time project.