Started on automatic upgrader

This commit is contained in:
Pavan Kumar Sunkara 2020-05-11 11:13:35 +02:00
parent 1a276f8f4f
commit 8bd1f1a9d3
5 changed files with 258 additions and 74 deletions

View file

@ -1,8 +1,149 @@
## Unreleased
TODO: Structopt and traits
TODO: `Shell`, `YamlLoader`
TODO: `cargo`, `std` features
#### BREAKING CHANGES
* **Removed**
* `From<&yaml_rust::yaml::Hash>` for `ArgGroup`
* **Macros**
* `_clap_count_exprs`
* **Renamed Methods**
* `App::set_term_width` => `App::term_width`
* `Arg::from_yaml` => `Arg::from`
* `Arg::with_name` => `Arg::new`
* `ArgGroup::from_yaml` => `ArgGroup::from`
* `ArgGroup::with_name` => `ArgGroup::new`
#### Features
* Added `Indices` that is returned by `ArgMatches::indices_of`
* **Added Methods**
* **Arg**
* `Arg::default_missing_value`
* `Arg::default_missing_value_os`
* `Arg::default_missing_values`
* `Arg::default_missing_values_os`
* `Arg::short_alias`
* `Arg::short_aliases`
* `Arg::visible_short_alias`
* `Arg::visible_short_aliases`
* **Added Variants**
* `AppSettings::DisableHelpFlags`
#### Enhancements
* `help_heading` defined on `Arg` now has higher priority than `App`
* Limited default text wrapping to 100 when `wrap_help` feature is not enabled
* Multiple bug fixes and error message improvements
<a name="v3.0.0-beta.1"></a>
## v3.0.0-beta.1 (2020-05-03)
#### Minimum Required Rust
* As of this release, `clap` requires `rustc 1.36.0` or greater.
* As of this release, `clap` requires `rustc 1.40.0` or greater.
#### BREAKING CHANGES
* **Removed**
* `SubCommand` in favor of `App`
* `SubCommand::with_name` => `App::new`
* `SubCommand::from_yaml` => `App::from`
* **App**
* `App::with_defaults`
* `App::version_message` in favor of `App::mut_arg`
* `App::version_short` in favor of `App::mut_arg`
* `App::help_message` in favor of `App::mut_arg`
* `App::help_short` in favor of `App::mut_arg`
* `App::arg_from_usage` in favor of `App::arg`
* `App::args_from_usage` in favor of TODO:
* `App::gen_completions` in favor of TODO:
* `App::gen_completions_to` in favor of TODO:
* `App::settings` in favor of `App::setting(Setting1 | Setting2)`
* `App::unset_settings` in favor of `App::unset_setting(Setting1 | Setting2)`
* `App::global_settings` in favor of `App::global_setting(Setting1 | Setting2)`
* **Arg**
* `Arg::empty_values` in favor of TODO:
* `ArgMatches::usage` in favor of `App::generate_usage`
* **Settings**
* `AppSettings::PropagateGlobalValuesDown`
* `ArgSettings::Global` in favor of `Arg::global` method
* `ArgSettings::Multiple` in favor of `ArgSettings::MultipleValues` and `ArgSettings::MultipleOccurrences`
* **Macros**
* `arg_enum!` in favor of `ArgEnum` derive macro.
* `value_t!` in favor of `ArgMatches::value_of_t`
* `value_t_or_exit!` in favor of `ArgMatches::value_of_t_or_exit`
* `values_t!` in favor of `ArgMatches::values_of_t`
* `values_t_or_exit!` in favor of `ArgMatches::values_of_t_or_exit`
* Support for `{n}` in help text
* **Renamed Methods**
* **App**
* `App::from_yaml` => `App::from`
* `App::arg_from_usage` => `App::arg`
* `App::help` => `App::override_help`
* `App::usage` => `App::override_usage`
* `App::template` => `App::help_template`
* `App::get_matches_safe` => `App::try_get_matches`
* `App::get_matches_from_safe` => `App::try_get_matches_from`
* `App::get_matches_from_safe_borrow` => `App::try_get_matches_from_mut`
* **Arg**
* `Arg::help` => `Arg::about`
* `Arg::from_usage` => `Arg::from`
* `Arg::set` => `Arg::setting`
* `Arg::unset` => `Arg::unset_setting`
* **Renamed Variants**
* `ArgSettings::CaseInsensitive` => `ArgSettings::IgnoreCase`
* `ArgSettings::AllowLeadingHyphen` => `ArgSettings::AllowHyphenValues`
* `ArgSettings::EmptyValues` => `ArgSettings::AllowEmptyValues`
* `ArgSettings::CaseInsensitive` => `ArgSettings::IgnoreCase`
* **Renamed Fields**
* `Error::message` => `Error::cause`
* **Changed**
* `App::write_help` is now a mutable reference instance method (takes `&mut self`)
* `Arg::short` now accepts `char` instead of `&str`
* `Arg::validator` now takes first argument as `Fn(&str) -> Result<O, E: ToString>` instead of
`Fn(String) -> Result<(), String>`
* `Arg::validator_os` now takes first argument as `Fn(&OsStr) -> Result<O, OsString>` instead of
`Fn(&OsStr) -> Result<(), OsString>`
* In usage parser, for options `[name]... --option [val]` results in `ArgSettings::MultipleOccurrences`
but `--option [val]...` results in `ArgSettings::MultipleValues` *and* `ArgSettings::MultipleOccurrences`.
Before both resulted in the same thing
* `App` and `Arg` now need only one lifetime
* Allow empty values is no longer the default
* UseValueDelimiter is no longer the default
* `App::override_usage` no longer implies `\t` which allows multi lined usages
#### Features
* **Added Methods**
* **App**
* `App::replace`
* `App::get_matches_mut`
* `App::mut_arg`
* `App::unset_global_setting`
* `App::help_heading`
* `App::stop_custom_headings`
* **Arg**
* `Arg::exclusive`
* `Arg::multiple_values`
* `Arg::multiple_occurrences`
* `Arg::help_heading`
* **Added Variants**
* `AppSettings::HelpRequired`
* `AppSettings::NoAutoHelp`
* `AppSettings::NoAutoVersion`
* `ArgSettings::SubcommandPrecedenceOverArg`
#### Enhancements
* Made `App::arg` and `App::args` more generic
* Improvements to `clap_app!` macro to make it support more wider use cases
* Colors now work correctly on Windows Console
* Multiple bug fixes and error message improvements
* Improvements to parsing logic and help messages
<a name="v2.29.2"></a>
## v2.29.2 (2018-01-16)

View file

@ -18,9 +18,9 @@ homepage = "https://clap.rs/"
keywords = [
"clap",
"cli",
"parse",
"derive",
"proc_macro",
"parse"
"proc_macro"
]
categories = ["command-line-interface", "development-tools::procedural-macro-helpers"]
license = "MIT OR Apache-2.0"

37
clap_up/Cargo.toml Normal file
View file

@ -0,0 +1,37 @@
[package]
name = "clap_up"
version = "0.0.0"
edition = "2018"
authors = [
"Pavan Kumar Sunkara <pavan.sss1991@gmail.com>",
"Clap Maintainers",
]
description = "Automatic code upgrader for Clap"
repository = "https://github.com/clap-rs/clap/tree/master/clap_up"
homepage = "https://clap.rs/"
keywords = [
"clap",
"cli",
"upgrader",
"cargo-up",
]
categories = []
license = "MIT OR Apache-2.0"
readme = "README.md"
[badges]
is-it-maintained-issue-resolution = { repository = "clap-rs/clap" }
is-it-maintained-open-issues = { repository = "clap-rs/clap" }
maintenance = {status = "actively-developed"}
[lib]
bench = false
[dependencies]
cargo-up = { path = "../../../pksunkara/cargo-up/cargo-up" }
[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
[package.metadata.workspaces]
independent = true

77
clap_up/src/lib.rs Normal file
View file

@ -0,0 +1,77 @@
use cargo_up::{
ra_hir::Semantics, ra_ide_db::RootDatabase, ra_syntax::ast, Runner, Upgrader, Version,
};
pub fn runner() -> Runner {
Runner::new()
.minimum("2.33.0")
.unwrap()
.version(
Version::new("3.0.0-beta.1")
.unwrap()
.peers(&["structopt"])
// .replace("clap::args::SubCommand", "App")
// .replace_dep("structopt", "clap", features = ["derive"])
.rename_methods(
"structopt::StructOpt",
&[
["from_args", "parse"],
["from_iter", "parse_from"],
["from_iter_safe", "try_parse_from"],
["from_clap", "from_arg_matches"],
["clap", "into_app"],
],
)
.rename_methods(
"clap::app::App",
&[
["from_yaml", "from"],
["arg_from_usage", "arg"],
["help", "override_help"],
["usage", "override_usage"],
["template", "help_template"],
["get_matches_safe", "try_get_matches"],
["get_matches_from_safe", "try_get_matches_from"],
["get_matches_from_safe_borrow", "try_get_matches_from_mut"],
],
)
.rename_methods(
"clap::args::arg::Arg",
&[
["help", "about"],
["from_usage", "from"],
["set", "setting"],
["unset", "unset_setting"],
],
)
.rename_methods(
"clap::args::subcommand::SubCommand",
&[["with_name", "new"], ["from_yaml", "from"]],
)
.rename_members("clap::errors::Error", &[["message", "cause"]])
.hook_method_call_expr(&print_method_calls),
)
.version(
Version::new("3.0.0-rc.0")
.unwrap()
.rename_methods("clap::build::app::App", &[["set_term_width", "term_width"]])
.rename_methods(
"clap::build::arg::Arg",
&[["from_yaml", "from"], ["with_name", "new"]],
)
.rename_methods(
"clap::build::arg_group::ArgGroup",
&[["from_yaml", "from"], ["with_name", "new"]],
),
)
}
fn print_method_calls(
upgrader: &mut Upgrader,
method_call_expr: &ast::MethodCallExpr,
semantics: &Semantics<RootDatabase>,
) {
if let Some(name_ref) = method_call_expr.name_ref() {
// println!("method: {}", name_ref.text());
}
}

View file

@ -1,71 +0,0 @@
# Highlights
* Lazy propagation
* Lazy requirement validation
* `App::write_help` takes `&mut self` now
* `App::override_usage` No longer implies `\t` which allows multi lined usages
* In usage parser, for options `[name]... --option [val]` results in `ArgSettings::MultipleOccurrences` but `--option [val]...` results in `ArgSettings::MultipleValues` *and* `ArgSettings::MultipleOccurrences`. Before both resulted in the same thing
* Allow empty values no longer default
* UseValueDelimiter no longer the default
* Multiple delima fixed (vals vs occurrences)
* Ability to mutate args once they've been added to an `App`
* `App::args` and `App::arg` are more generic
* Can unset global settings
* Instead of adding arg with long `--help` or `--version` you can use `App::mut_arg` to override things
* Caution, must fully override
* No longer forces auto-handle of help/ver however if still desired `AppSettings::NoAuto{Help,Version}`
# How to Upgrade
### If you use `Arg::multiple(true)`
# Deprecations
## Simple Renames
### App
- `App::get_matches_safe` -> `App::try_get_matches`
- `App::get_matches_from_safe` -> `App::try_get_matches_from`
- `App::get_matches_safe_borrow` -> `App::try_get_matches_from_mut`
- `App::usage` -> `App::override_usage`
- `App::help` -> `App::override_help`
- `App::template` -> `App::help_template`
### Arg
- `Arg::unset` -> `Arg::unset_setting`
- `Arg::set` -> `Arg::setting`
## Structural Changes
### App
- `App::version_message` -> `App::mut_arg`
- `App::version_short` -> `App::mut_arg`
- `App::help_message` -> `App::mut_arg`
- `App::help_short` -> `App::mut_arg`
- `App::args_from_usage` -> `App::args(&str)`
- `App::arg_from_usage` -> `App::arg(&str)`
- `App::write_help` -> `&self` -> `&mut self` (#808)
- `App::gen_completions` -> `clap_completions::generate`
- `App::gen_completions_to` -> `clap_completions::generate_to`
- `App::settings` -> `App::setting(Setting1 | Setting2)`
- `App::unset_settings` -> `App::unset_setting(Setting1 | Setting2)`
- `App::global_settings` -> `App::global_setting(Setting1 | Setting2)`
### Arg
- `Arg::from_usage` -> `Arg::from(&str)`
# Additional APIs
## App
* `App::mut_arg`
* `App::unset_global_setting`
## Arg