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

Infer short completion descriptions for commandline flags #7804

Merged
merged 2 commits into from
Feb 13, 2023

Conversation

PJungkamp
Copy link
Contributor

Motivation

Descriptions for commandline flags may not include newlines and should be rather short for display in a shell.
The current completion code asserts that a description does not contain newlines.
Current descriptions for e.g. -I trigger that assertion and break commandline flag completion.

Context

See #7792

Here I shorten the description by truncating the string on '\n' or '.' to and add an ellipsis ' [...]' if sensible.
I chose to split on \n as well as . to keep the descriptions a single sentence.
I also had to trim at least an empty line from the front of the string to make -I work.

This yields something like the following for fish:

$ nix shell -
-c                                     (Command and arguments to be executed, defaulting to `$SHELL`)
-f  (Interpret installables as attribute paths relative to the Nix expression stored in *file* [...])
-I                                                          (Add *path* to the Nix search path [...])
-i                              (Clear the entire environment (except those specified with `--keep`))
-j                                                            (The maximum number of parallel builds)
-k                                                             (Keep the environment variable *name*)
-L                                                          (Print full build logs on standard error)
-u                                                            (Unset the environment variable *name*)
-v                                                             (Increase the logging verbosity level)
--                                                                                                   

Checklist for maintainers

Maintainers: tick if completed or explain if not relevant

  • agreed on idea
  • agreed on implementation strategy
  • tests, as appropriate
    • functional tests - tests/**.sh
    • unit tests - src/*/tests
    • integration tests - tests/nixos/*
  • documentation in the manual
  • code and comments are self-explanatory
  • commit message explains why the change was made
  • new feature or incompatible change: updated release notes

Descriptions for commandline flags may not include newlines and should
be rather short for display in a shell. Truncate the description string
of a flag on '\n' or '.' to and add an ellipsis if needed.
src/libutil/args.cc Outdated Show resolved Hide resolved
@edolstra edolstra merged commit 2037f8a into NixOS:master Feb 13, 2023
@PJungkamp PJungkamp deleted the fix-completions branch February 13, 2023 15:34
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.

None yet

2 participants