1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 11:07:44 +00:00

coreutils: clap 3

This commit is contained in:
Terts Diepraam 2022-01-11 15:45:02 +01:00
parent 49e5412580
commit c93298f32c
3 changed files with 11 additions and 11 deletions

View file

@ -244,7 +244,8 @@ test = [ "uu_test" ]
[workspace] [workspace]
[dependencies] [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" } lazy_static = { version="1.3" }
textwrap = { version="0.14", features=["terminal_size"] } textwrap = { version="0.14", features=["terminal_size"] }
uucore = { version=">=0.0.10", package="uucore", path="src/uucore" } uucore = { version=">=0.0.10", package="uucore", path="src/uucore" }

View file

@ -43,7 +43,7 @@ pub fn main() {
let mut tf = File::create(Path::new(&out_dir).join("test_modules.rs")).unwrap(); let mut tf = File::create(Path::new(&out_dir).join("test_modules.rs")).unwrap();
mf.write_all( mf.write_all(
"type UtilityMap<T> = HashMap<&'static str, (fn(T) -> i32, fn() -> App<'static, 'static>)>;\n\ "type UtilityMap<T> = HashMap<&'static str, (fn(T) -> i32, fn() -> App<'static>)>;\n\
\n\ \n\
fn util_map<T: uucore::Args>() -> UtilityMap<T> {\n\ fn util_map<T: uucore::Args>() -> UtilityMap<T> {\n\
\t#[allow(unused_mut)]\n\ \t#[allow(unused_mut)]\n\

View file

@ -5,9 +5,8 @@
// For the full copyright and license information, please view the LICENSE // For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code. // file that was distributed with this source code.
use clap::App; use clap::{App, Arg};
use clap::Arg; use clap_complete::Shell;
use clap::Shell;
use std::cmp; use std::cmp;
use std::collections::hash_map::HashMap; use std::collections::hash_map::HashMap;
use std::ffi::OsStr; use std::ffi::OsStr;
@ -143,13 +142,13 @@ fn gen_completions<T: uucore::Args>(
let matches = App::new("completion") let matches = App::new("completion")
.about("Prints completions to stdout") .about("Prints completions to stdout")
.arg( .arg(
Arg::with_name("utility") Arg::new("utility")
.possible_values(&all_utilities) .possible_values(all_utilities)
.required(true), .required(true),
) )
.arg( .arg(
Arg::with_name("shell") Arg::new("shell")
.possible_values(&Shell::variants()) .possible_values(Shell::possible_values())
.required(true), .required(true),
) )
.get_matches_from(std::iter::once(OsString::from("completion")).chain(args)); .get_matches_from(std::iter::once(OsString::from("completion")).chain(args));
@ -165,12 +164,12 @@ fn gen_completions<T: uucore::Args>(
let shell: Shell = shell.parse().unwrap(); let shell: Shell = shell.parse().unwrap();
let bin_name = std::env::var("PROG_PREFIX").unwrap_or_default() + utility; 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(); io::stdout().flush().unwrap();
process::exit(0); process::exit(0);
} }
fn gen_coreutils_app<T: uucore::Args>(util_map: UtilityMap<T>) -> App<'static, 'static> { fn gen_coreutils_app<T: uucore::Args>(util_map: UtilityMap<T>) -> App<'static> {
let mut app = App::new("coreutils"); let mut app = App::new("coreutils");
for (_, (_, sub_app)) in util_map { for (_, (_, sub_app)) in util_map {
app = app.subcommand(sub_app()); app = app.subcommand(sub_app());