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

More anchors + new features: :hide-header:, :nested: complete, :post-process: #147

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

TomerGodinger
Copy link

Summary

This adds the following features:

  1. :hide-header: option: omits the title and description from the output.
  2. :nested: complete option: produces a fuller listing with title, description, usage, short summary and then full nested details. Feel free to change the name to whatever you want if you choose to keep it. =)
  3. :post-process: path.to.module:func_name option: invokes the specified function in the specified module on the list of generated nodes for each command. The function should get the command used and the list of nodes that were generated.

This also adds quite a few new anchors for cross-referencing - namely one for each .. program:: directive, and for options and environment variables, an anchor is added per option name. For example, for a command group grp, command cmd, an option that has the flags -f and --flag and an environment variable env that provides a default for it, the following anchors will be created:

  • grp-cmd-f
  • grp-cmd-flag
  • grp-cmd-f-env
  • grp-cmd-flag-env

This has a caveat which I haven't dealt with, which is collisions.
Having an option with the flag names -f and --f would cause the same anchor to be created twice. Similarly a command called cmd with the flag --some-flag and a command called cmd-some with the flag --flag would both create the anchor cmd-some-flag. It may be a good idea to change the format so it's injective.
This actually applies to existing anchors as well, e.g. group grp + command some-cmd + option opt would yield the same option anchor as group grp-some + command cmd + option opt, if I'm not mistaken.
A decision not to support this would be valid, of course, but it's something that begs consideration at the least.

Tasks

  • Added unit tests
  • Added documentation for new features (where applicable)
  • Added release notes (using reno)
  • Ran test suite and style checks and built documentation (tox)

Further details

This is the same PR as #100, fixed to work with the modern code.
I wanted to get this open already so I used what I have now - I'll look at reno later for the release notes.
This can also use some more tests.

Add anchors to all the Click components (i.e. groups and commands),
along with another general one for options so that now using the full
path of the component with separating dashes is always a valid
reference. E.g. for a group "mygroup", command "mycommand" and option
"-myoption", all of the following work:

  :ref:`My Group <mygroup>`
  :ref:`My Command <mygroup-mycommand>`
  :ref:`My Option <mygroup-mycommand-myoption>`
  :option:`My Option <mygroup-mycommand -myoption>`
Adding :hide-header: to the directive will hide the title, description
and usage and only show the commands. This also means that the commands
will not be under a single section, but rather add a section each to
where the directive is located.

The ":nested: complete" option shows the name, description, usage, short
command overview (basically the entire ":nested: short" option) followed
by the details of the commands from the ":nested: full" option.
By providing the option ":post-process: module.path:funcion", the user
can direct the directive to run the provided function on the command and
its generated node for each command processed. This allows for full
per-command customization of the output.
The usage was removed when :hide-header: was used with full nesting before. This should make it behave the same as it does with short nesting.
This adds documentation for `complete` nesting, `:hide-header:` and `:post-process:`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant