File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ pub fn cli() -> Command {
1616 . arg_silent_suggestion ( )
1717 . arg_package_spec_simple (
1818 "Package to clean artifacts for" ,
19- ArgValueCandidates :: new ( Vec :: new ) , // TODO(completions): implement dynamic completion for `cargo clean -p`
19+ ArgValueCandidates :: new ( get_pkg_name_candidates ) ,
2020 )
2121 . arg_release ( "Whether or not to clean release artifacts" )
2222 . arg_profile ( "Clean artifacts of the specified profile" )
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ use home::cargo_home_with_cwd;
2828use indexmap:: IndexSet ;
2929use itertools:: Itertools ;
3030use semver:: Version ;
31- use std:: collections:: { HashMap , HashSet } ;
31+ use std:: collections:: { BTreeMap , HashMap , HashSet } ;
3232use std:: ffi:: { OsStr , OsString } ;
3333use std:: path:: Path ;
3434use std:: path:: PathBuf ;
@@ -1445,6 +1445,26 @@ pub fn get_pkg_id_spec_candidates() -> Vec<clap_complete::CompletionCandidate> {
14451445 candidates
14461446}
14471447
1448+ pub fn get_pkg_name_candidates ( ) -> Vec < clap_complete:: CompletionCandidate > {
1449+ let packages: BTreeMap < _ , _ > = get_packages ( )
1450+ . unwrap_or_default ( )
1451+ . into_iter ( )
1452+ . map ( |package| {
1453+ (
1454+ package. name ( ) ,
1455+ package. manifest ( ) . metadata ( ) . description . clone ( ) ,
1456+ )
1457+ } )
1458+ . collect ( ) ;
1459+
1460+ packages
1461+ . into_iter ( )
1462+ . map ( |( name, description) | {
1463+ clap_complete:: CompletionCandidate :: new ( name. as_str ( ) ) . help ( description. map ( From :: from) )
1464+ } )
1465+ . collect ( )
1466+ }
1467+
14481468fn get_packages ( ) -> CargoResult < Vec < Package > > {
14491469 let gctx = new_gctx_for_completions ( ) ?;
14501470
You can’t perform that action at this time.
0 commit comments