Skip to content

Commit

Permalink
docs: Clarify the default state of an Arg/field
Browse files Browse the repository at this point in the history
Inspired by https://www.reddit.com/r/rust/comments/1i5np88/clap_documentation_is_too_confusing_for_me/m87mutm/

> > I always use derive, and I mostly use the reference. From manual
> experimentation I’ve had to develop the mental model that short
> implicitly is what makes an argument non-positional, and if I want an
> argument to be positional then it will be by default unless I specify
> short. When I search for the word “positional” in the reference, there
> are no results. When I search for it in the tutorial, there is one
> result that says something I can do with an argument that i’ve made
> positional, but there’s no indication for how to make the argument
> positional in the first place. The reference documentation on short
> doesn’t mention anything about the fact that that’s what determines
> whether an argument is positional, even when I click through to the
> builder documentation on Arg::short.
  • Loading branch information
epage committed Jan 20, 2025
1 parent f89134d commit 0a73271
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions clap_builder/src/builder/arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ impl Arg {
/// The name is used to check whether or not the argument was used at
/// runtime, get values, set relationships with other args, etc..
///
/// By default, an `Arg` is
/// - Positional, see [`Arg::short`] or [`Arg::long`] turn it into an option
/// - Accept a single value, see [`Arg::action`] to override this
///
/// <div class="warning">
///
/// **NOTE:** In the case of arguments that take values (i.e. [`Arg::action(ArgAction::Set)`])
Expand Down
2 changes: 1 addition & 1 deletion src/_derive/_tutorial/chapter_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//!
//! ### Positionals
//!
//! You can have users specify values by their position on the command-line:
//! By default, struct fields define positional arguments:
//!
//! ```rust
#![doc = include_str!("../../../examples/tutorial_derive/03_03_positional.rs")]
Expand Down
3 changes: 3 additions & 0 deletions src/_derive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@
//! ### Arg Attributes
//!
//! These correspond to a [`Arg`][crate::Arg].
//! The default state for a field without attributes is to be a positional argument with [behavior
//! inferred from the field type](#arg-types).
//! `#[arg(...)]` attributes allow overriding or extending those defaults.
//!
//! **Raw attributes:** Any [`Arg` method][crate::Arg] can also be used as an attribute, see [Terminology](#terminology) for syntax.
//! - e.g. `#[arg(num_args(..=3))]` would translate to `arg.num_args(..=3)`
Expand Down
2 changes: 1 addition & 1 deletion src/_tutorial/chapter_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//!
//! ### Positionals
//!
//! You can have users specify values by their position on the command-line:
//! By default, an [`Arg`] defines a positional argument:
//!
//! ```rust
#![doc = include_str!("../../examples/tutorial_builder/03_03_positional.rs")]
Expand Down

0 comments on commit 0a73271

Please sign in to comment.