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

cmd: add 'help' subcommand to zpool and zfs #15288

Merged
merged 1 commit into from
Sep 19, 2023
Merged

Conversation

robn
Copy link
Member

@robn robn commented Sep 17, 2023

Motivation and Context

program help subcommand is a reasonably common pattern for multifunction command-line programs.

At the very least, I use git help and cargo help fairly often, and I find myself typing zfs help or zpool help often enough, and being annoyed that I didn't land in the manpage. So something in me is expecting it to happen, and there's precedent, and I suggest (with no data to back it up at all) that it goes some way to make a command-line program more approachable and discoverable.

(I am willing to turn in my "old-timey-sysadmin" membership card if that's what it takes!)

Description

This commit adds support for that style to the zpool and zfs commands.

When run as zpool help [<topic>] or zfs help [<topic>], executes the man program on the PATH with the most likely manpage name for the requested topic: zpool-<topic> or zfs-<topic> for subcommands, or zpool<topic> or zfs<topic> for the concepts and props topics. If no topic is supplied, uses the top zpool or zfs pages.

There's loads more that could be done here, from being smarter about how the manpage names are constructed, to allowing alternate viewers or documentation formats (especially on non-Unix platforms). You might run git help help for ideas if you haven't seen this before.

How Has This Been Tested?

Tested by hand on Linux and FreeBSD:

FreeBSD:

$ ./zfs help | head -1
ZFS(8)                  FreeBSD System Manager's Manual                 ZFS(8)
$ ./zfs help list | head -1
ZFS-LIST(8)             FreeBSD System Manager's Manual            ZFS-LIST(8)
$ ./zfs help props | head -1
ZFSPROPS(7)        FreeBSD Miscellaneous Information Manual        ZFSPROPS(7)
$ ./zfs help badpage
No manual entry for zfs-badpage

Linux:

$ ./zpool help | head -1
ZPOOL(8)                  BSD System Manager's Manual                 ZPOOL(8)
$ ./zpool help import | head -1
ZPOOL-IMPORT(8)           BSD System Manager's Manual          ZPOOL-IMPORT(8)
$ ./zpool help concepts | head -1
ZPOOLCONCEPTS(7)     BSD Miscellaneous Information Manual     ZPOOLCONCEPTS(7)
$ ./zpool help dunno
No manual entry for zpool-dunno

(the difference in page title is because its just calling man, so showing the system manpages, which are slighly rebranded on FreeBSD's builtin OpenZFS).

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Library ABI change (libzfs, libzfs_core, libnvpair, libuutil and libzfsbootenv)
  • Documentation (a change to man pages or other documentation)

Checklist:

Copy link
Contributor

@behlendorf behlendorf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice addition. My only gripe is that it appears to cause cli_root/zfs_program/zfs_program_json to fail.

'program help subcommand' is a reasonably common pattern for
multifunction command-line programs. This commit adds support for that
style to the zpool and zfs commands.

When run as 'zpool help [<topic>]' or 'zfs help [<topic>]', executes the
'man' program on the PATH with the most likely manpage name for the
requested topic: "zpool-<topic>" or "zfs-<topic>" for subcommands, or
"zpool<topic>" or "zfs<topic>" for the "concepts" and "props" topics.
If no topic is supplied, uses the top "zpool" or "zfs" pages.

Signed-off-by: Rob Norris <[email protected]>
@behlendorf behlendorf added the Status: Code Review Needed Ready for review and testing label Sep 19, 2023
@robn
Copy link
Member Author

robn commented Sep 19, 2023

Confirmed. Surprised me! That test includes the common usage trailer for all commands, which this PR changed. Feels like a bit of a brittle test (I'd at least prefer a "starts with" check) but I'm not interested in understanding and reworking it now, so I've just pushed an update to match the trailer. Lets see how this run goes.

@behlendorf behlendorf added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels Sep 19, 2023
@behlendorf behlendorf merged commit 7228ba1 into openzfs:master Sep 19, 2023
17 of 19 checks passed
behlendorf pushed a commit to behlendorf/zfs that referenced this pull request Sep 20, 2023
'program help subcommand' is a reasonably common pattern for
multifunction command-line programs. This commit adds support for that
style to the zpool and zfs commands.

When run as 'zpool help [<topic>]' or 'zfs help [<topic>]', executes the
'man' program on the PATH with the most likely manpage name for the
requested topic: "zpool-<topic>" or "zfs-<topic>" for subcommands, or
"zpool<topic>" or "zfs<topic>" for the "concepts" and "props" topics.
If no topic is supplied, uses the top "zpool" or "zfs" pages.

Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Kay Pedersen <[email protected]>
Signed-off-by: Rob Norris <[email protected]>
Closes openzfs#15288
behlendorf pushed a commit to behlendorf/zfs that referenced this pull request Sep 21, 2023
'program help subcommand' is a reasonably common pattern for
multifunction command-line programs. This commit adds support for that
style to the zpool and zfs commands.

When run as 'zpool help [<topic>]' or 'zfs help [<topic>]', executes the
'man' program on the PATH with the most likely manpage name for the
requested topic: "zpool-<topic>" or "zfs-<topic>" for subcommands, or
"zpool<topic>" or "zfs<topic>" for the "concepts" and "props" topics.
If no topic is supplied, uses the top "zpool" or "zfs" pages.

Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Kay Pedersen <[email protected]>
Signed-off-by: Rob Norris <[email protected]>
Closes openzfs#15288
behlendorf pushed a commit that referenced this pull request Sep 22, 2023
'program help subcommand' is a reasonably common pattern for
multifunction command-line programs. This commit adds support for that
style to the zpool and zfs commands.

When run as 'zpool help [<topic>]' or 'zfs help [<topic>]', executes the
'man' program on the PATH with the most likely manpage name for the
requested topic: "zpool-<topic>" or "zfs-<topic>" for subcommands, or
"zpool<topic>" or "zfs<topic>" for the "concepts" and "props" topics.
If no topic is supplied, uses the top "zpool" or "zfs" pages.

Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Kay Pedersen <[email protected]>
Signed-off-by: Rob Norris <[email protected]>
Closes #15288
robn added a commit to robn/zfs that referenced this pull request Oct 3, 2023
'program help subcommand' is a reasonably common pattern for
multifunction command-line programs. This commit adds support for that
style to the zpool and zfs commands.

When run as 'zpool help [<topic>]' or 'zfs help [<topic>]', executes the
'man' program on the PATH with the most likely manpage name for the
requested topic: "zpool-<topic>" or "zfs-<topic>" for subcommands, or
"zpool<topic>" or "zfs<topic>" for the "concepts" and "props" topics.
If no topic is supplied, uses the top "zpool" or "zfs" pages.

Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Kay Pedersen <[email protected]>
Signed-off-by: Rob Norris <[email protected]>
Closes openzfs#15288
lundman pushed a commit to openzfsonwindows/openzfs that referenced this pull request Dec 12, 2023
'program help subcommand' is a reasonably common pattern for
multifunction command-line programs. This commit adds support for that
style to the zpool and zfs commands.

When run as 'zpool help [<topic>]' or 'zfs help [<topic>]', executes the
'man' program on the PATH with the most likely manpage name for the
requested topic: "zpool-<topic>" or "zfs-<topic>" for subcommands, or
"zpool<topic>" or "zfs<topic>" for the "concepts" and "props" topics.
If no topic is supplied, uses the top "zpool" or "zfs" pages.

Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Kay Pedersen <[email protected]>
Signed-off-by: Rob Norris <[email protected]>
Closes openzfs#15288
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Accepted Ready to integrate (reviewed, tested)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants