Skip to content

Commit

Permalink
Improve documentation, add shell support table
Browse files Browse the repository at this point in the history
  • Loading branch information
intgr committed Jul 31, 2020
1 parent e3b5391 commit 8bc558d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions clap_generate/src/generators/shells/fish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ fn value_completion(option: &Arg) -> String {
if let Some(ref data) = option.get_possible_values() {
format!(" -r -f -a \"{}\"", data.join(" "))
} else {
// NB! If you change this, please also update the table in `ValueHint` documentation.
match option.get_value_hint() {
ValueHint::Unknown => " -r",
// fish has no built-in support to distinguish these
Expand Down
1 change: 1 addition & 0 deletions clap_generate/src/generators/shells/zsh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ fn value_completion(arg: &Arg) -> Option<String> {
.join(" ")
))
} else {
// NB! If you change this, please also update the table in `ValueHint` documentation.
Some(
match arg.get_value_hint() {
ValueHint::Unknown => {
Expand Down
32 changes: 28 additions & 4 deletions src/build/arg/value_hint.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
use std::str::FromStr;

/// Provides hints about argument types for shell command completion.
///
/// See the `clap_generate` crate for completion script generation.
///
/// Overview of which hints are supported by which shell:
///
/// | Hint | zsh | fish |
/// | ---------------------- | --- | ------- |
/// | `AnyPath` | Yes | Yes |
/// | `FilePath` | Yes | Yes |
/// | `DirPath` | Yes | Yes |
/// | `ExecutablePath` | Yes | Partial |
/// | `CommandName` | Yes | Yes |
/// | `CommandString` | Yes | Partial |
/// | `CommandWithArguments` | Yes | |
/// | `Username` | Yes | Yes |
/// | `Hostname` | Yes | Yes |
/// | `Url` | Yes | |
/// | `EmailAddress` | Yes | |
#[derive(Debug, PartialEq, Copy, Clone)]
pub enum ValueHint {
/// Default value if hint is not specified. Follows shell default behavior, which is usually
Expand All @@ -20,15 +38,21 @@ pub enum ValueHint {
CommandName,
/// A single string containing a command and its arguments.
CommandString,
/// A command and each argument as multiple strings. Common for command wrappers.
/// Capture the remaining arguments as a command name and arguments for that command. This is
/// common when writing shell wrappers that execute anther command, for example `sudo` or `env`.
///
/// This hint is special, the argument must be a positional argument and use `.multiple(true)`.
/// It's also recommended to use `AppSettings::TrailingVarArg` to avoid confusion about which
/// command the following options belong to.
/// This hint is special, the argument must be a positional argument and have
/// [`.multiple(true)`] and App must use [`AppSettings::TrailingVarArg`]. The result is that the
/// command line `my_app ls -la /` will be parsed as `["ls", "-la", "/"]` and clap won't try to
/// parse the `-la` argument itself.
///
/// [`.multiple(true)`]: ./struct.Arg.html#method.multiple
/// [`AppSettings::TrailingVarArg`]: ./enum.AppSettings.html#variant.TrailingVarArg
CommandWithArguments,
/// Name of a local operating system user.
Username,
/// Host name of a computer.
/// Shells usually parse `/etc/hosts` and `.ssh/known_hosts` to complete hostnames.
Hostname,
/// Complete web address.
Url,
Expand Down

0 comments on commit 8bc558d

Please sign in to comment.