|
| 1 | +# clap compatibility |
| 2 | + |
| 3 | +This matrix describes compatibility with `clap` 4.6.6 and `clap_derive` 4.6.4, the |
| 4 | +versions audited in this workspace. It distinguishes what a CLI can declare directly with |
| 5 | +`usage` from what [`clap_usage`](/spec/integrations/clap) can recover from an existing |
| 6 | +`clap::Command`. |
| 7 | + |
| 8 | +The bridge is not a lossless migration verifier. clap exposes some settings only through |
| 9 | +setters, so `clap_usage` cannot detect that they were present. Migrate from the Rust declaration, |
| 10 | +not only from generated KDL, when a row says **usage only**. |
| 11 | + |
| 12 | +## Status |
| 13 | + |
| 14 | +| Status | Meaning | |
| 15 | +| --------------- | ------------------------------------------------------------------------------------------ | |
| 16 | +| **Supported** | The derive, compiled parser, spec, and reference parser carry the behavior. | |
| 17 | +| **Usage only** | A usage declaration carries it, but clap exposes no getter or the bridge loses part of it. | |
| 18 | +| **Partial** | The common form works; the note names the unsupported part. | |
| 19 | +| **Different** | usage intentionally has different parsing behavior. | |
| 20 | +| **Unsupported** | No equivalent is available yet. | |
| 21 | +| **Non-goal** | The API shape is outside the static-parser architecture. | |
| 22 | + |
| 23 | +## Types and declarations |
| 24 | + |
| 25 | +| clap | usage | clap → spec | Notes | |
| 26 | +| ------------------------------------------------ | ----------- | -------------- | --------------------------------------------------------------------------------------------------------- | |
| 27 | +| `Parser` | Supported | Supported | `#[derive(usage::Cli)]` | |
| 28 | +| `Args` | Supported | Supported | `#[derive(usage::Args)]`, including `flatten` | |
| 29 | +| `Subcommand` | Supported | Supported | Nested and boxed variants are supported. | |
| 30 | +| `ValueEnum` | Partial | Partial | Bare values and names work; aliases, hidden values, per-value help, and case-insensitive matching do not. | |
| 31 | +| `#[arg(skip)]` | Supported | Not applicable | `#[usage(skip)]`; skipped fields do not belong in a spec. | |
| 32 | +| arbitrary `Command` / `Arg` builder code | Non-goal | Partial | `usage-lib` is the dynamic spec interpreter; usage derive does not reproduce clap's builder API. | |
| 33 | +| `ArgMatches`, `FromArgMatches`, `CommandFactory` | Non-goal | Not applicable | Typed structs are built directly from static tables. | |
| 34 | +| `update_from` / `try_update_from` | Unsupported | Not applicable | A parse currently constructs a new value. | |
| 35 | + |
| 36 | +## Arguments and values |
| 37 | + |
| 38 | +| clap | usage | clap → spec | Notes | |
| 39 | +| ----------------------------------------- | ----------- | -------------- | ----------------------------------------------------------------------------------------------------------------- | |
| 40 | +| long and short flags | Supported | Supported | Multiple visible aliases are supported. Hidden flag aliases are bridge-lossy. | |
| 41 | +| positional arguments | Supported | Supported | Required, optional, and variadic positionals are supported. | |
| 42 | +| `Option<T>`, `Vec<T>`, `Option<Vec<T>>` | Supported | Not applicable | Values use `FromStr`; Unix `PathBuf` and `OsString` also accept non-UTF-8 bytes. | |
| 43 | +| `ArgAction::SetTrue`, `SetFalse`, `Count` | Supported | Supported | `SetFalse` is `#[usage(negate)]`. | |
| 44 | +| `default_value` | Supported | Supported | Defaults are applied after argv and environment values. | |
| 45 | +| `default_missing_value` | Usage only | Unsupported | `#[usage(default_missing = "…")]`; clap has no getter. | |
| 46 | +| `default_value_if(s)` | Usage only | Unsupported | `#[usage(default_if(...))]`; clap has no getter. | |
| 47 | +| `env` | Supported | Partial | Environment fallback works, but the current bridge can lose the binding. | |
| 48 | +| `value_delimiter` | Supported | Supported | ASCII delimiters round-trip. | |
| 49 | +| `num_args` | Partial | Partial | `var_min` / `var_max` cover ranges; fixed arity, distinct value names, and bridge preservation remain incomplete. | |
| 50 | +| `allow_hyphen_values` | Supported | Supported | Available on value-taking flags; trailing positionals use `double_dash = "automatic"`. | |
| 51 | +| `allow_negative_numbers` | Unsupported | Unsupported | `allow_hyphen_values` is broader, not equivalent. | |
| 52 | +| `require_equals` | Supported | Supported | Detached values are refused. | |
| 53 | +| `value_terminator` | Unsupported | Unsupported | No spec spelling yet. | |
| 54 | +| `dont_delimit_trailing_values` | Unsupported | Unsupported | No spec spelling yet. | |
| 55 | +| possible-values parser | Supported | Supported | Use `ValueEnum` or `choices`. | |
| 56 | +| arbitrary `value_parser` / numeric ranges | Unsupported | Unsupported | `FromStr` validates conversion, but there is no per-field validator or declarative range yet. | |
| 57 | +| `ValueHint` | Partial | Partial | Path hints used by completions work; the full clap vocabulary does not. | |
| 58 | + |
| 59 | +## Relationships and command routing |
| 60 | + |
| 61 | +| clap | usage | clap → spec | Notes | |
| 62 | +| --------------------------------------------------------- | ----------- | ----------- | ---------------------------------------------------------------------------------------------------------- | |
| 63 | +| `required`, `conflicts_with`, `overrides_with` | Supported | Supported | Environment values participate in post-binding checks. | |
| 64 | +| `requires` | Usage only | Unsupported | clap exposes setters but no getter. | |
| 65 | +| `requires_if(s)` | Usage only | Unsupported | Presence and value-conditional forms are supported in usage. | |
| 66 | +| `required_if_eq`, `required_unless_present` | Partial | Partial | Common single-selector forms work; the complete all/any families do not. | |
| 67 | +| `ArgGroup`, required groups, `exclusive` | Supported | Supported | Positional group members are not represented yet. | |
| 68 | +| positional conflicts and relationships | Unsupported | Unsupported | Spec selectors currently name flags. | |
| 69 | +| global flags | Supported | Supported | A global may occur once per selected command scope. | |
| 70 | +| `allow_external_subcommands` | Supported | Supported | Use an `#[usage(external_subcommand)]` catch-all variant. | |
| 71 | +| `multicall` | Supported | Supported | `parse()` routes on the executable basename. | |
| 72 | +| `no_binary_name` | Unsupported | Unsupported | Low-level usage-argv already receives argv without argv0; no clap-compatible setter exists. | |
| 73 | +| `infer_subcommands`, `infer_long_args` | Unsupported | Unsupported | Diagnostics suggest likely names but do not accept prefixes. | |
| 74 | +| `arg_required_else_help` and subcommand/argument policies | Unsupported | Unsupported | No command-policy vocabulary yet. | |
| 75 | +| unknown flags | Different | Different | The spec can choose strict errors; the reference parser may forward unknown flag-like data to positionals. | |
| 76 | + |
| 77 | +## Help, version, and generated artifacts |
| 78 | + |
| 79 | +| clap | usage | clap → spec | Notes | |
| 80 | +| ------------------------------------------------- | ----------- | -------------- | ------------------------------------------------------------------------------------ | |
| 81 | +| short and long help | Supported | Supported | The compiled renderer is checked against usage-lib across the jdx CLI fleet. | |
| 82 | +| help headings | Supported | Supported | Flags and arguments are grouped by heading. | |
| 83 | +| hidden commands, flags, and arguments | Supported | Supported | Granular hides for defaults, env, and possible values are unsupported. | |
| 84 | +| doc comments and long help | Supported | Supported | First paragraph is short help; the full block is long help. | |
| 85 | +| `verbatim_doc_comment` | Unsupported | Not applicable | Doc comments are normalized. | |
| 86 | +| `help_template`, `next_line_help`, `flatten_help` | Unsupported | Unsupported | No equivalent yet. | |
| 87 | +| `term_width`, `max_term_width` | Unsupported | Unsupported | Help wraps using `COLUMNS`. | |
| 88 | +| help styles and color | Partial | Unsupported | Diagnostics are styled; help output is not. | |
| 89 | +| built-in help/version flag control | Unsupported | Unsupported | Custom help/version actions and disabling built-ins are not represented. | |
| 90 | +| `--version` / `-V` | Supported | Supported | Version propagation is supported. | |
| 91 | +| completions | Partial | Supported | Self-contained bash, fish, PowerShell, and zsh scripts are available; Elvish is not. | |
| 92 | +| KDL, markdown, and manpages | Supported | Supported | Emitted KDL feeds the existing generators without a runtime dependency. | |
| 93 | + |
| 94 | +## Usage extensions |
| 95 | + |
| 96 | +These are not clap compatibility gaps. usage additionally supports `mount`, `restart_token`, |
| 97 | +`default_subcommand`, command and flag `effect`, Nushell completions, and a language-neutral |
| 98 | +conformance corpus. clap cannot express those properties, so a clap-generated spec cannot carry |
| 99 | +them without an overlay. |
| 100 | + |
| 101 | +This page is the compatibility baseline, not a claim that every clap builder method is covered. |
| 102 | +When clap is updated, audit new public derive attributes and relevant `Command`, `Arg`, and |
| 103 | +`PossibleValue` methods here before treating the update as migration-neutral. |