Skip to content

Commit

Permalink
Merge pull request #53 from epage/migrate
Browse files Browse the repository at this point in the history
docs: Clean up 3.0 changelog
  • Loading branch information
epage authored Dec 3, 2021
2 parents e751d5e + 75d4178 commit aeb2958
Show file tree
Hide file tree
Showing 26 changed files with 530 additions and 1,496 deletions.
740 changes: 196 additions & 544 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/build/app/debug_asserts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ pub(crate) fn assert_app(app: &App) {
}

assert!(
!(arg.is_set(ArgSettings::Required) && arg.global),
!(arg.is_set(ArgSettings::Required) && arg.get_global()),
"Global arguments cannot be required.\n\n\t'{}' is marked as both global and required",
arg.name
);
Expand Down
100 changes: 75 additions & 25 deletions src/build/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl<'help> App<'help> {
/// this `App`.
pub fn get_arg_conflicts_with(&self, arg: &Arg) -> Vec<&Arg<'help>> // FIXME: This could probably have been an iterator
{
if arg.global {
if arg.get_global() {
self.get_global_arg_conflicts_with(arg)
} else {
arg.blacklist
Expand Down Expand Up @@ -422,34 +422,26 @@ impl<'help> App<'help> {
)
};

let mut has_metadata = false;

for (k, v) in yaml {
a = match k.as_str().expect("App fields must be strings") {
"_has_metadata" => {
has_metadata = true;
a
}
"bin_name" => yaml_to_str!(a, v, bin_name),
"version" => yaml_to_str!(a, v, version),
"long_version" => yaml_to_str!(a, v, long_version),
"author" => yaml_to_str!(a, v, author),
"bin_name" => yaml_to_str!(a, v, bin_name),
"about" => yaml_to_str!(a, v, about),
"long_about" => yaml_to_str!(a, v, long_about),
"before_help" => yaml_to_str!(a, v, before_help),
"before_long_help" => yaml_to_str!(a, v, before_long_help),
"after_help" => yaml_to_str!(a, v, after_help),
"after_long_help" => yaml_to_str!(a, v, after_long_help),
"help_heading" => yaml_to_str!(a, v, help_heading),
"help_template" => yaml_to_str!(a, v, help_template),
"override_help" => yaml_to_str!(a, v, override_help),
"override_usage" => yaml_to_str!(a, v, override_usage),
"template" => yaml_to_str!(a, v, help_template),
"usage" => yaml_to_str!(a, v, override_usage),
"help" => yaml_to_str!(a, v, override_help),
"help_message" => yaml_to_str!(a, v, help_message),
"version_message" => yaml_to_str!(a, v, version_message),
"alias" => yaml_to_str!(a, v, alias),
"aliases" => yaml_vec_or_str!(a, v, alias),
"visible_alias" => yaml_to_str!(a, v, visible_alias),
"visible_aliases" => yaml_vec_or_str!(a, v, visible_alias),
"display_order" => yaml_to_usize!(a, v, display_order),
"term_width" => yaml_to_usize!(a, v, term_width),
"max_term_width" => yaml_to_usize!(a, v, max_term_width),
"args" => {
if let Some(vec) = v.as_vec() {
for arg_yaml in vec {
Expand Down Expand Up @@ -486,13 +478,7 @@ impl<'help> App<'help> {
"global_setting" | "global_settings" => {
yaml_to_setting!(a, v, global_setting, AppSettings, "AppSetting", err)
}
"name" => continue,
s => {
if !has_metadata {
panic!("Unknown setting '{}' in YAML file for {}", s, err)
}
continue;
}
_ => a,
}
}

Expand Down Expand Up @@ -869,6 +855,30 @@ impl<'help> App<'help> {
self.override_help(help)
}

/// Deprecated, replaced with [`App::mut_arg`]
#[deprecated(since = "3.0.0", note = "Replaced with `App::mut_arg`")]
pub fn help_short(self, c: char) -> Self {
self.mut_arg("help", |a| a.short(c))
}

/// Deprecated, replaced with [`App::mut_arg`]
#[deprecated(since = "3.0.0", note = "Replaced with `App::mut_arg`")]
pub fn version_short(self, c: char) -> Self {
self.mut_arg("version", |a| a.short(c))
}

/// Deprecated, replaced with [`App::mut_arg`]
#[deprecated(since = "3.0.0", note = "Replaced with `App::mut_arg`")]
pub fn help_message(self, s: impl Into<&'help str>) -> Self {
self.mut_arg("help", |a| a.help(s.into()))
}

/// Deprecated, replaced with [`App::mut_arg`]
#[deprecated(since = "3.0.0", note = "Replaced with `App::mut_arg`")]
pub fn version_message(self, s: impl Into<&'help str>) -> Self {
self.mut_arg("version", |a| a.help(s.into()))
}

/// Sets the help template to be used, overriding the default format.
///
/// **NOTE:** The template system is by design very simple. Therefore, the
Expand Down Expand Up @@ -954,6 +964,15 @@ impl<'help> App<'help> {
self
}

/// Deprecated, replaced with [`App::setting(a| b)`]
#[deprecated(since = "3.0.0", note = "Replaced with `App::setting(a | b)`")]
pub fn settings(mut self, settings: &[AppSettings]) -> Self {
for s in settings {
self.settings.insert((*s).into());
}
self
}

/// Remove a setting for the current command or subcommand.
///
/// See [`AppSettings`] for a full list of possibilities and examples.
Expand Down Expand Up @@ -983,6 +1002,15 @@ impl<'help> App<'help> {
self
}

/// Deprecated, replaced with [`App::unset_setting(a| b)`]
#[deprecated(since = "3.0.0", note = "Replaced with `App::unset_setting(a | b)`")]
pub fn unset_settings(mut self, settings: &[AppSettings]) -> Self {
for s in settings {
self.settings.remove((*s).into());
}
self
}

/// Apply a setting for the current command and all subcommands.
///
/// See [`App::setting`] to apply a setting only to this command.
Expand All @@ -1004,6 +1032,16 @@ impl<'help> App<'help> {
self
}

/// Deprecated, replaced with [`App::global_setting(a| b)`]
#[deprecated(since = "3.0.0", note = "Replaced with `App::global_setting(a | b)`")]
pub fn global_settings(mut self, settings: &[AppSettings]) -> Self {
for s in settings {
self.settings.insert((*s).into());
self.g_settings.insert((*s).into());
}
self
}

/// Remove a setting and stop propagating down to subcommands.
///
/// See [`AppSettings`] for a full list of possibilities and examples.
Expand Down Expand Up @@ -1983,6 +2021,12 @@ impl<'help> App<'help> {
self._render_version(false)
}

/// Deprecated, replaced with [`App::render_version`]
#[deprecated(since = "3.0.0", note = "Replaced with `App::render_version`")]
pub fn write_version<W: Write>(&self, w: &mut W) -> ClapResult<()> {
write!(w, "{}", self.render_version()).map_err(From::from)
}

/// Version message rendered as if the user ran `--version`.
///
/// See also [`App::render_version`].
Expand All @@ -2007,6 +2051,12 @@ impl<'help> App<'help> {
self._render_version(true)
}

/// Deprecated, replaced with [`App::render_long_version`]
#[deprecated(since = "3.0.0", note = "Replaced with `App::render_long_version`")]
pub fn write_long_version<W: Write>(&self, w: &mut W) -> ClapResult<()> {
write!(w, "{}", self.render_long_version()).map_err(From::from)
}

/// Usage statement
///
/// ### Examples
Expand Down Expand Up @@ -2465,7 +2515,7 @@ impl<'help> App<'help> {
let global_args: Vec<_> = self
.args
.args()
.filter(|a| a.global)
.filter(|a| a.get_global())
.map(|ga| ga.id.clone())
.collect();
if let Some(used_subcommand) = matcher.0.subcommand.as_ref() {
Expand Down Expand Up @@ -2608,7 +2658,7 @@ impl<'help> App<'help> {
debug!("App::_propagate_global_args:{}", self.name);

for sc in &mut self.subcommands {
for a in self.args.args().filter(|a| a.global) {
for a in self.args.args().filter(|a| a.get_global()) {
let mut propagate = false;
let is_generated = matches!(
a.provider,
Expand Down
4 changes: 2 additions & 2 deletions src/build/app/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ impl_settings! { AppSettings, AppFlags,
=> Flags::DISABLE_HELP_SC,
DisableHelpFlag("disablehelpflag")
=> Flags::DISABLE_HELP_FLAG,
DisableHelpFlags("disablehelpflag")
DisableHelpFlags("disablehelpflags")
=> Flags::DISABLE_HELP_FLAG,
DisableVersionFlag("disableversionflag")
=> Flags::DISABLE_VERSION_FLAG,
DisableVersion("disableversionflag")
DisableVersion("disableversion")
=> Flags::DISABLE_VERSION_FLAG,
PropagateVersion("propagateversion")
=> Flags::PROPAGATE_VERSION,
Expand Down
Loading

0 comments on commit aeb2958

Please sign in to comment.