-
Notifications
You must be signed in to change notification settings - Fork 258
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
feat(cargo-shuttle): generate manpage #1388
Conversation
Introduce a new option `--manpage` for the `generate` subcommand to generate manpage with clap-mangen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just needs a bit of tweaking 🐻
…ional Make `--shell` optional and remove the `env` attribute; otherwise it interferes with the `--manpage` option. Rendering to standard output is a better choice just like we do for shell completions.
cargo-shuttle/src/args.rs
Outdated
#[arg(short, long)] | ||
shell: Option<Shell>, | ||
/// Output to a file (stdout by default) | ||
#[arg(short, long, env)] | ||
output: Option<PathBuf>, | ||
/// Generate manpage to the standard output | ||
#[arg(short, long)] | ||
manpage: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since they are mutually exclusive, it feels cleaner if they were separate subcommands: cargo shuttle generate shell <SHELL>
and cargo shuttle generate manpage
. Although a breaking change, could this be acceptable? @oddgrd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The OUTPUT
env var usage feels weird as well. Could be a risk of collision with other programs using it. How do we feel about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah using OUTPUT
is a bit risky. OTOH although the subcommand approach might look cleaner it would add unnecessary complexity to the code IMO. But I'm fine with either way - and I would say let's have this ready soon and not get caught up into discussion too much 🐻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since they are mutually exclusive, it feels cleaner if they were separate subcommands:
cargo shuttle generate shell <SHELL>
andcargo shuttle generate manpage
. Although a breaking change, could this be acceptable?
I think having them as separate subcommands makes the most sense. Regarding the output
arg, we could remove the env. That makes two breaking changes, but I doubt it will affect many (if any) users.
I've added the changes and updated the PR description. Apologies for any mistakes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works, but the manpage only contains the global args and references other manpages for each subcommand (not very useful in our case), and I can find any way to generate proper manpages for subcommands or make the default manpage contain the manuals for all subcommands 🤔
2bd4068
to
bea5bf9
Compare
Yeah you're right; it doesn't have much 😅 . I think to have manual for the sub-commands as well, we need to iterate over them using |
And since we're outputting to stdout, I wonder how we can do separate man pages for the sub-commands. As for dumping everything into one manual, maybe we can do this: fn generate_manpage(&self) -> Result<CommandOutcome> {
let app = Command::command();
let output = std::io::stdout();
let mut output_handle = output.lock();
Man::new(app.clone()).render(&mut output_handle)?;
for subcommand in app.get_subcommands().cloned() {
Man::new(subcommand.clone()).render(&mut output_handle)?;
if subcommand.has_subcommands() {
for sb in subcommand.get_subcommands().cloned() {
Man::new(sb).render(&mut output_handle)?;
}
}
}
Ok(CommandOutcome::Ok)
} Just wanted to discuss the approach without bloating the commit history. 😅 |
I quickly tested changing the input Command to Man to be a subcommand, but the result was an empty manpage, so not sure what was happening there. |
If you find a way to get everything into one manual, go for it. |
We should now have everything in the man page. |
Cool. I see that a lot of parts are repeated (title and footer for each manpage), so we could customize which parts of the manpage are printed for each section to make it more unified. |
Ah yes. Pretty sure it's the title section of the man pages that's repeating. I don't think |
They do have |
We should have less repetitions now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and LGTM
Add the ability to generate man page for
cargo-shuttle
.Description of change
Summary
cargo-shuttle
.generate
sub-commandsshell
andmanpage
to generate shell completions and man page respectively (breaking API change).Details
Introduces a new sub-command
manpage
for thegenerate
sub-command to generate man page with clap-mangen.To verify the changes, we can run the following from the project root
shuttle
:This generates the man page in the current working directory by default. We can set a custom directory by setting theOUT_DIR
environment variable:This generates the man page and renders it to the standard output. You can redirect the output to a
.1
man page file and read it withman
:cargo run --package cargo-shuttle -- generate manpage > cargo-shuttle.1 man -l cargo-shuttle.1
Brings both shell completions and man page generation under separate
generate
sub-commands. For shell completions, this means now you must generate shell completions with the following command:Instead of the previous API:
The output option for shell completion no longer relies on the value of the
OUTPUT
environment variable. If you want a custom path, use the--output
option withgenerate shell
:Closes #1377.
How has this been tested? (if applicable)
Please see the change description above.