Skip to content

Commit

Permalink
docs: Annotate with required features
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Oct 9, 2021
1 parent e8ec11e commit 122c227
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@ jobs:
if: matrix.features == 'all'
with:
command: test
args: --features "wrap_help yaml regex unstable-replace"
args: --features "wrap_help yaml regex unstable-replace nightly"
- name: Check debug
uses: actions-rs/cargo@v1
if: matrix.features == 'all'
with:
command: check
args: --features "wrap_help yaml regex unstable-replace debug"
args: --features "wrap_help yaml regex unstable-replace nightly debug"
- name: Test release
uses: actions-rs/cargo@v1
if: matrix.features == 'release'
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ unicode = ["textwrap/unicode-width", "unicase"] # Support for unicode character
# Optional
wrap_help = ["terminal_size", "textwrap/terminal_size"]
yaml = ["yaml-rust"]
nightly = []

# In-work features
unstable-replace = []
Expand All @@ -117,7 +118,7 @@ lto = true
codegen-units = 1

[package.metadata.docs.rs]
features = ["yaml", "regex", "unstable-replace"]
features = ["yaml", "regex", "unstable-replace", "nightly"]
targets = ["x86_64-unknown-linux-gnu"]

[workspace]
Expand Down
4 changes: 2 additions & 2 deletions src/build/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1437,8 +1437,6 @@ impl<'help> App<'help> {

/// Replaces an argument or subcommand used on the CLI at runtime with other arguments or subcommands.
///
/// **Note:** This is gated behind [`unstable-replace`](https://github.com/clap-rs/clap/issues/2836)
///
/// When this method is used, `name` is removed from the CLI, and `target`
/// is inserted in its place. Parsing continues as if the user typed
/// `target` instead of `name`.
Expand Down Expand Up @@ -1542,6 +1540,7 @@ impl<'help> App<'help> {
/// [`App::replace`]: App::replace()
#[inline]
#[cfg(feature = "unstable-replace")]
#[cfg_attr(feature = "nightly", doc(cfg(feature = "unstable-replace")))]
pub fn replace(mut self, name: &'help str, target: &'help [&'help str]) -> Self {
self.replacers.insert(name, target);
self
Expand Down Expand Up @@ -2837,6 +2836,7 @@ impl<'help> Index<&'_ Id> for App<'help> {
}

#[cfg(feature = "yaml")]
#[cfg_attr(feature = "nightly", doc(cfg(feature = "yaml")))]
impl<'help> From<&'help Yaml> for App<'help> {
#[allow(clippy::cognitive_complexity)]
fn from(y: &'help Yaml) -> Self {
Expand Down
7 changes: 7 additions & 0 deletions src/build/arg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ impl<'help> Arg<'help> {
/// assert_eq!(Some(OsStr::new("ENVIRONMENT")), arg.get_env());
/// ```
#[cfg(feature = "env")]
#[cfg_attr(feature = "nightly", doc(cfg(feature = "env")))]
pub fn get_env(&self) -> Option<&OsStr> {
self.env.as_ref().map(|x| x.0)
}
Expand Down Expand Up @@ -2295,6 +2296,7 @@ impl<'help> Arg<'help> {
/// assert_eq!(res.err().unwrap().kind, ErrorKind::ValueValidation)
/// ```
#[cfg(feature = "regex")]
#[cfg_attr(feature = "nightly", doc(cfg(feature = "regex")))]
pub fn validator_regex(
self,
regex: impl Into<RegexRef<'help>>,
Expand Down Expand Up @@ -3219,6 +3221,7 @@ impl<'help> Arg<'help> {
/// [`Arg::takes_value(true)`]: Arg::takes_value()
/// [`Arg::use_delimiter(true)`]: Arg::use_delimiter()
#[cfg(feature = "env")]
#[cfg_attr(feature = "nightly", doc(cfg(feature = "env")))]
#[inline]
pub fn env(self, name: &'help str) -> Self {
self.env_os(OsStr::new(name))
Expand All @@ -3228,6 +3231,7 @@ impl<'help> Arg<'help> {
/// from the environment if available in the exact same manner as [`Arg::env`] only using
/// [`OsStr`]s instead.
#[cfg(feature = "env")]
#[cfg_attr(feature = "nightly", doc(cfg(feature = "env")))]
#[inline]
pub fn env_os(mut self, name: &'help OsStr) -> Self {
self.env = Some((name, env::var_os(name)));
Expand Down Expand Up @@ -4019,6 +4023,7 @@ impl<'help> Arg<'help> {
/// If we were to run the above program with `--help` the `[env: MODE]` portion of the help
/// text would be omitted.
#[cfg(feature = "env")]
#[cfg_attr(feature = "nightly", doc(cfg(feature = "env")))]
#[inline]
pub fn hide_env(self, hide: bool) -> Self {
if hide {
Expand Down Expand Up @@ -4057,6 +4062,7 @@ impl<'help> Arg<'help> {
/// If we were to run the above program with `$ CONNECT=super_secret connect --help` the
/// `[default: CONNECT=super_secret]` portion of the help text would be omitted.
#[cfg(feature = "env")]
#[cfg_attr(feature = "nightly", doc(cfg(feature = "env")))]
#[inline]
pub fn hide_env_values(self, hide: bool) -> Self {
if hide {
Expand Down Expand Up @@ -4786,6 +4792,7 @@ impl<'help> Arg<'help> {
}

#[cfg(feature = "yaml")]
#[cfg_attr(feature = "nightly", doc(cfg(feature = "yaml")))]
impl<'help> From<&'help Yaml> for Arg<'help> {
/// Creates a new instance of [`Arg`] from a .yaml (YAML) file.
///
Expand Down
1 change: 1 addition & 0 deletions src/build/arg/regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::borrow::Cow;
///
/// [`Cow`]: std::borrow::Cow
#[derive(Debug, Clone)]
#[cfg_attr(feature = "nightly", doc(cfg(feature = "regex")))]
pub struct RegexRef<'a>(Cow<'a, Regex>);

impl<'a> Deref for RegexRef<'a> {
Expand Down
2 changes: 2 additions & 0 deletions src/build/arg/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,12 @@ pub enum ArgSettings {
IgnoreCase,
/// Hides environment variable arguments from the help message
#[cfg(feature = "env")]
#[cfg_attr(feature = "nightly", doc(cfg(feature = "env")))]
HideEnv,
/// Hides any values currently assigned to ENV variables in the help message (good for sensitive
/// information)
#[cfg(feature = "env")]
#[cfg_attr(feature = "nightly", doc(cfg(feature = "env")))]
HideEnvValues,
/// The argument should **not** be shown in short help text
HiddenShortHelp,
Expand Down
1 change: 1 addition & 0 deletions src/build/arg_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ impl<'help> From<&'_ ArgGroup<'help>> for ArgGroup<'help> {
}

#[cfg(feature = "yaml")]
#[cfg_attr(feature = "nightly", doc(cfg(feature = "yaml")))]
impl<'help> From<&'help Yaml> for ArgGroup<'help> {
/// Creates a new instance of `ArgGroup` from a .yaml (YAML) file.
///
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#![forbid(unsafe_code)]
// TODO: https://github.com/rust-lang/rust-clippy/issues/7290
#![allow(clippy::single_component_path_imports)]
#![cfg_attr(feature = "nightly", feature(doc_cfg))]

#[cfg(not(feature = "std"))]
compile_error!("`std` feature is currently required to build `clap`");
Expand Down
7 changes: 7 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
/// # }
/// ```
#[cfg(feature = "yaml")]
#[cfg_attr(feature = "nightly", doc(cfg(feature = "yaml")))]
#[macro_export]
macro_rules! load_yaml {
($yaml:expr) => {
Expand All @@ -49,6 +50,7 @@ macro_rules! load_yaml {
/// # }
/// ```
#[cfg(feature = "cargo")]
#[cfg_attr(feature = "nightly", doc(cfg(feature = "cargo")))]
#[macro_export]
macro_rules! crate_license {
() => {{
Expand Down Expand Up @@ -79,6 +81,7 @@ macro_rules! crate_license {
/// # }
/// ```
#[cfg(feature = "cargo")]
#[cfg_attr(feature = "nightly", doc(cfg(feature = "cargo")))]
#[macro_export]
macro_rules! crate_version {
() => {
Expand Down Expand Up @@ -108,6 +111,7 @@ macro_rules! crate_version {
/// # }
/// ```
#[cfg(feature = "cargo")]
#[cfg_attr(feature = "nightly", doc(cfg(feature = "cargo")))]
#[macro_export]
macro_rules! crate_authors {
($sep:expr) => {{
Expand Down Expand Up @@ -138,6 +142,7 @@ macro_rules! crate_authors {
/// # }
/// ```
#[cfg(feature = "cargo")]
#[cfg_attr(feature = "nightly", doc(cfg(feature = "cargo")))]
#[macro_export]
macro_rules! crate_description {
() => {
Expand All @@ -159,6 +164,7 @@ macro_rules! crate_description {
/// # }
/// ```
#[cfg(feature = "cargo")]
#[cfg_attr(feature = "nightly", doc(cfg(feature = "cargo")))]
#[macro_export]
macro_rules! crate_name {
() => {
Expand Down Expand Up @@ -190,6 +196,7 @@ macro_rules! crate_name {
/// # }
/// ```
#[cfg(feature = "cargo")]
#[cfg_attr(feature = "nightly", doc(cfg(feature = "cargo")))]
#[macro_export]
macro_rules! app_from_crate {
() => {
Expand Down
1 change: 1 addition & 0 deletions src/parse/matches/matched_arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::INTERNAL_ERROR_MSG;
pub(crate) enum ValueType {
Unknown,
#[cfg(feature = "env")]
#[cfg_attr(feature = "nightly", doc(cfg(feature = "env")))]
EnvVariable,
CommandLine,
DefaultValue,
Expand Down

0 comments on commit 122c227

Please sign in to comment.