From c93298f32c24cb331c492503d019217413ad3bf2 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Tue, 11 Jan 2022 15:45:02 +0100 Subject: [PATCH] coreutils: clap 3 --- Cargo.toml | 3 ++- build.rs | 2 +- src/bin/coreutils.rs | 17 ++++++++--------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8310c3329..b2fbb426c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -244,7 +244,8 @@ test = [ "uu_test" ] [workspace] [dependencies] -clap = { version = "2.33", features = ["wrap_help"] } +clap = { version = "3.0", features = ["wrap_help", "cargo"] } +clap_complete = "3.0" lazy_static = { version="1.3" } textwrap = { version="0.14", features=["terminal_size"] } uucore = { version=">=0.0.10", package="uucore", path="src/uucore" } diff --git a/build.rs b/build.rs index 293d2e65f..cfe6ce6bc 100644 --- a/build.rs +++ b/build.rs @@ -43,7 +43,7 @@ pub fn main() { let mut tf = File::create(Path::new(&out_dir).join("test_modules.rs")).unwrap(); mf.write_all( - "type UtilityMap = HashMap<&'static str, (fn(T) -> i32, fn() -> App<'static, 'static>)>;\n\ + "type UtilityMap = HashMap<&'static str, (fn(T) -> i32, fn() -> App<'static>)>;\n\ \n\ fn util_map() -> UtilityMap {\n\ \t#[allow(unused_mut)]\n\ diff --git a/src/bin/coreutils.rs b/src/bin/coreutils.rs index 1de1b6354..e83b6f697 100644 --- a/src/bin/coreutils.rs +++ b/src/bin/coreutils.rs @@ -5,9 +5,8 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -use clap::App; -use clap::Arg; -use clap::Shell; +use clap::{App, Arg}; +use clap_complete::Shell; use std::cmp; use std::collections::hash_map::HashMap; use std::ffi::OsStr; @@ -143,13 +142,13 @@ fn gen_completions( let matches = App::new("completion") .about("Prints completions to stdout") .arg( - Arg::with_name("utility") - .possible_values(&all_utilities) + Arg::new("utility") + .possible_values(all_utilities) .required(true), ) .arg( - Arg::with_name("shell") - .possible_values(&Shell::variants()) + Arg::new("shell") + .possible_values(Shell::possible_values()) .required(true), ) .get_matches_from(std::iter::once(OsString::from("completion")).chain(args)); @@ -165,12 +164,12 @@ fn gen_completions( let shell: Shell = shell.parse().unwrap(); let bin_name = std::env::var("PROG_PREFIX").unwrap_or_default() + utility; - app.gen_completions_to(bin_name, shell, &mut io::stdout()); + clap_complete::generate(shell, &mut app, bin_name, &mut io::stdout()); io::stdout().flush().unwrap(); process::exit(0); } -fn gen_coreutils_app(util_map: UtilityMap) -> App<'static, 'static> { +fn gen_coreutils_app(util_map: UtilityMap) -> App<'static> { let mut app = App::new("coreutils"); for (_, (_, sub_app)) in util_map { app = app.subcommand(sub_app());