Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: EXPERIMENT: Move from &'b str to Cow<'static, str> #1728

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions clap_derive/src/derives/dummies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ pub fn clap_enum(name: &Ident) {
pub fn into_app(name: &Ident) {
append_dummy(quote! {
impl ::clap::IntoApp for #name {
fn into_app<'b>() -> ::clap::App<'b> {
fn into_app<'b>() -> ::clap::App {
unimplemented!()
}
fn augment_clap<'b>(_app: ::clap::App<'b>) -> ::clap::App<'b> {
fn augment_clap<'b>(_app: ::clap::App) -> ::clap::App {
unimplemented!()
}
}
Expand All @@ -46,7 +46,7 @@ pub fn subcommand(name: &Ident) {
fn from_subcommand(_name: &str, _matches: Option<&::clap::ArgMatches>) -> Option<Self> {
unimplemented!()
}
fn augment_subcommands(_app: ::clap::App<'_>) -> ::clap::App<'_> {
fn augment_subcommands(_app: ::clap::App) -> ::clap::App {
unimplemented!()
}
}
Expand Down
8 changes: 4 additions & 4 deletions clap_derive/src/derives/into_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ pub fn gen_for_enum(name: &syn::Ident) -> TokenStream {

quote! {
impl ::clap::IntoApp for #name {
fn into_app<'b>() -> ::clap::App<'b> {
fn into_app<'b>() -> ::clap::App {
let app = ::clap::App::new(#app_name)
.setting(::clap::AppSettings::SubcommandRequiredElseHelp);
<#name as ::clap::IntoApp>::augment_clap(app)
}

fn augment_clap<'b>(app: ::clap::App<'b>) -> ::clap::App<'b> {
fn augment_clap<'b>(app: ::clap::App) -> ::clap::App {
<#name as ::clap::Subcommand>::augment_subcommands(app)
}
}
Expand All @@ -74,7 +74,7 @@ fn gen_into_app_fn(attrs: &[syn::Attribute]) -> GenOutput {
let name = attrs.cased_name();

let tokens = quote! {
fn into_app<'b>() -> ::clap::App<'b> {
fn into_app<'b>() -> ::clap::App {
Self::augment_clap(::clap::App::new(#name))
}
};
Expand All @@ -89,7 +89,7 @@ fn gen_augment_clap_fn(
let app_var = syn::Ident::new("app", proc_macro2::Span::call_site());
let augmentation = gen_app_augmentation(fields, &app_var, parent_attribute);
quote! {
fn augment_clap<'b>(#app_var: ::clap::App<'b>) -> ::clap::App<'b> {
fn augment_clap<'b>(#app_var: ::clap::App) -> ::clap::App {
#augmentation
}
}
Expand Down
2 changes: 1 addition & 1 deletion clap_derive/src/derives/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn gen_augment_subcommands(
let app_methods = parent_attribute.top_level_methods();
let version = parent_attribute.version();
quote! {
fn augment_subcommands<'b>(app: ::clap::App<'b>) -> ::clap::App<'b> {
fn augment_subcommands<'b>(app: ::clap::App) -> ::clap::App {
let app = app #app_methods;
#( #subcommands )*;
app #version
Expand Down
4 changes: 2 additions & 2 deletions clap_derive/tests/ui/non_existent_attr.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0599]: no method named `non_existing_attribute` found for type `clap::build::arg::Arg<'_>` in the current scope
error[E0599]: no method named `non_existing_attribute` found for type `clap::build::arg::Arg` in the current scope
--> $DIR/non_existent_attr.rs:14:19
|
14 | #[clap(short, non_existing_attribute = 1)]
| ^^^^^^^^^^^^^^^^^^^^^^ method not found in `clap::build::arg::Arg<'_>`
| ^^^^^^^^^^^^^^^^^^^^^^ method not found in `clap::build::arg::Arg`
10 changes: 5 additions & 5 deletions clap_generate/src/generators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub trait Generator {
/// **NOTE:** `path` should not contain the root `bin_name`.
///
/// [clap]: ../clap/struct.App.html
fn find_subcommand_with_path<'b>(p: &'b App<'b>, path: Vec<&str>) -> &'b App<'b> {
fn find_subcommand_with_path<'b>(p: &'b App, path: Vec<&str>) -> &'b App {
let mut app = p;

for sc in path {
Expand Down Expand Up @@ -114,7 +114,7 @@ pub trait Generator {

/// Gets all the short options and flags of a [`clap::App`](../clap/struct.App.html).
/// Includes `h` and `V` depending on the [`clap::AppSettings`](../clap/enum.AppSettings.html).
fn shorts<'b>(p: &'b App<'b>) -> Vec<char> {
fn shorts<'b>(p: &'b App) -> Vec<char> {
debugln!("shorts: name={}", p.name);

let mut shorts: Vec<char> = p
Expand Down Expand Up @@ -143,7 +143,7 @@ pub trait Generator {

/// Gets all the long options and flags of a [`clap::App`](../clap/struct.App.html).
/// Includes `help` and `version` depending on the [`clap::AppSettings`](../clap/enum.AppSettings.html).
fn longs<'b>(p: &'b App<'b>) -> Vec<String> {
fn longs<'b>(p: &'b App) -> Vec<String> {
debugln!("longs: name={}", p.name);

let mut longs: Vec<String> = p
Expand Down Expand Up @@ -174,7 +174,7 @@ pub trait Generator {

/// Gets all the flags of a [`clap::App`](../clap/struct.App.html).
/// Includes `help` and `version` depending on the [`clap::AppSettings`](../clap/enum.AppSettings.html).
fn flags<'b>(p: &'b App<'b>) -> Vec<Arg> {
fn flags<'b>(p: &'b App) -> Vec<Arg> {
debugln!("flags: name={}", p.name);

let mut flags: Vec<_> = flags!(p).cloned().collect();
Expand Down Expand Up @@ -218,7 +218,7 @@ mod tests {
}
}

fn common() -> App<'static> {
fn common() -> App {
let mut app = App::new("myapp")
.subcommand(
App::new("test")
Expand Down
6 changes: 1 addition & 5 deletions clap_generate/src/generators/shells/elvish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ fn get_tooltip<T: ToString>(help: Option<&str>, data: T) -> String {
}
}

fn generate_inner<'b>(
p: &'b App<'b>,
previous_command_name: &str,
names: &mut Vec<&'b str>,
) -> String {
fn generate_inner<'b>(p: &'b App, previous_command_name: &str, names: &mut Vec<&'b str>) -> String {
debugln!("Elvish::generate_inner;");

let command_name = if previous_command_name.is_empty() {
Expand Down
6 changes: 1 addition & 5 deletions clap_generate/src/generators/shells/powershell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ fn get_tooltip<T: ToString>(help: Option<&str>, data: T) -> String {
}
}

fn generate_inner<'b>(
p: &'b App<'b>,
previous_command_name: &str,
names: &mut Vec<&'b str>,
) -> String {
fn generate_inner<'b>(p: &'b App, previous_command_name: &str, names: &mut Vec<&'b str>) -> String {
debugln!("PowerShell::generate_inner;");

let command_name = if previous_command_name.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion clap_generate/src/generators/shells/zsh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ esac",
)
}

fn parser_of<'b>(p: &'b App<'b>, mut sc: &str) -> &'b App<'b> {
fn parser_of<'b>(p: &'b App, mut sc: &str) -> &'b App {
debugln!("Zsh::parser_of: sc={}", sc);

if sc == p.get_bin_name().unwrap_or(&String::new()) {
Expand Down
2 changes: 1 addition & 1 deletion clap_generate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub use generators::Generator;
///
/// use clap::{App, Arg};
///
/// pub fn build_cli() -> App<'static> {
/// pub fn build_cli() -> App {
/// App::new("compl")
/// .about("Tests completions")
/// .arg(Arg::with_name("file")
Expand Down
48 changes: 24 additions & 24 deletions clap_generate/tests/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static BASH: &'static str = r#"_myapp() {
myapp)
cmd="myapp"
;;

help)
cmd+="__help"
;;
Expand All @@ -51,23 +51,23 @@ static BASH: &'static str = r#"_myapp() {
return 0
fi
case "${prev}" in

*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
;;

myapp__help)
opts=" -h -V --help --version "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi
case "${prev}" in

*)
COMPREPLY=()
;;
Expand All @@ -82,7 +82,7 @@ static BASH: &'static str = r#"_myapp() {
return 0
fi
case "${prev}" in

--case)
COMPREPLY=($(compgen -f ${cur}))
return 0
Expand Down Expand Up @@ -164,14 +164,14 @@ _myapp_commands() {
(( $+functions[_myapp__help_commands] )) ||
_myapp__help_commands() {
local commands; commands=(

)
_describe -t commands 'myapp help commands' commands "$@"
}
(( $+functions[_myapp__test_commands] )) ||
_myapp__test_commands() {
local commands; commands=(

)
_describe -t commands 'myapp test commands' commands "$@"
}
Expand Down Expand Up @@ -492,28 +492,28 @@ _my_app_commands() {
(( $+functions[_my_app__help_commands] )) ||
_my_app__help_commands() {
local commands; commands=(

)
_describe -t commands 'my_app help commands' commands "$@"
}
(( $+functions[_my_app__some-cmd-with-hypens_commands] )) ||
_my_app__some-cmd-with-hypens_commands() {
local commands; commands=(

)
_describe -t commands 'my_app some-cmd-with-hypens commands' commands "$@"
}
(( $+functions[_my_app__some_cmd_commands] )) ||
_my_app__some_cmd_commands() {
local commands; commands=(

)
_describe -t commands 'my_app some_cmd commands' commands "$@"
}
(( $+functions[_my_app__test_commands] )) ||
_my_app__test_commands() {
local commands; commands=(

)
_describe -t commands 'my_app test commands' commands "$@"
}
Expand Down Expand Up @@ -552,7 +552,7 @@ static BASH_SPECIAL_CMDS: &'static str = r#"_my_app() {
my_app)
cmd="my_app"
;;

help)
cmd+="__help"
;;
Expand All @@ -578,23 +578,23 @@ static BASH_SPECIAL_CMDS: &'static str = r#"_my_app() {
return 0
fi
case "${prev}" in

*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
;;

my_app__help)
opts=" -h -V --help --version "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi
case "${prev}" in

*)
COMPREPLY=()
;;
Expand All @@ -609,7 +609,7 @@ static BASH_SPECIAL_CMDS: &'static str = r#"_my_app() {
return 0
fi
case "${prev}" in

*)
COMPREPLY=()
;;
Expand All @@ -624,7 +624,7 @@ static BASH_SPECIAL_CMDS: &'static str = r#"_my_app() {
return 0
fi
case "${prev}" in

--config)
COMPREPLY=($(compgen -f ${cur}))
return 0
Expand All @@ -643,7 +643,7 @@ static BASH_SPECIAL_CMDS: &'static str = r#"_my_app() {
return 0
fi
case "${prev}" in

--case)
COMPREPLY=($(compgen -f ${cur}))
return 0
Expand Down Expand Up @@ -699,24 +699,24 @@ _my_app() {
'-V[Prints version information]' \
'--version[Prints version information]' \
&& ret=0

}

(( $+functions[_my_app_commands] )) ||
_my_app_commands() {
local commands; commands=(

)
_describe -t commands 'my_app commands' commands "$@"
}

_my_app "$@""#;

fn build_app() -> App<'static> {
fn build_app() -> App {
build_app_with_name("myapp")
}

fn build_app_with_name(s: &'static str) -> App<'static> {
fn build_app_with_name(s: &'static str) -> App {
App::new(s)
.about("Tests completions")
.arg(Arg::with_name("file").help("some input file"))
Expand All @@ -730,7 +730,7 @@ fn build_app_with_name(s: &'static str) -> App<'static> {
)
}

fn build_app_special_commands() -> App<'static> {
fn build_app_special_commands() -> App {
build_app_with_name("my_app")
.subcommand(
App::new("some_cmd").about("tests other things").arg(
Expand All @@ -743,7 +743,7 @@ fn build_app_special_commands() -> App<'static> {
.subcommand(App::new("some-cmd-with-hypens").alias("hyphen"))
}

fn build_app_special_help() -> App<'static> {
fn build_app_special_help() -> App {
App::new("my_app")
.arg(
Arg::with_name("single-quotes")
Expand Down
Loading