Skip to content

Commit

Permalink
coreutils: clap 3
Browse files Browse the repository at this point in the history
  • Loading branch information
tertsdiepraam committed Jan 11, 2022
1 parent ebdfbef commit 91b632f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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\
fn util_map<T: uucore::Args>() -> UtilityMap<T> {\n\
\t#[allow(unused_mut)]\n\
Expand Down
17 changes: 8 additions & 9 deletions src/bin/coreutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -143,13 +142,13 @@ fn gen_completions<T: uucore::Args>(
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));
Expand All @@ -165,12 +164,12 @@ fn gen_completions<T: uucore::Args>(
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<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");
for (_, (_, sub_app)) in util_map {
app = app.subcommand(sub_app());
Expand Down

0 comments on commit 91b632f

Please sign in to comment.