1 use clap
::{Arg, ArgAction, Command}
;
4 let matches
= Command
::new("pacman")
5 .about("package manager utility")
7 .subcommand_required(true)
8 .arg_required_else_help(true)
9 .author("Pacman Development Team")
12 // Only a few of its arguments are implemented below.
17 .about("Query the package database.")
22 .help("search locally installed packages for matching strings")
23 .conflicts_with("info")
25 .multiple_values(true),
31 .conflicts_with("search")
32 .help("view package information")
34 .multiple_values(true),
39 // Only a few of its arguments are implemented below.
44 .about("Synchronize packages.")
49 .conflicts_with("info")
51 .multiple_values(true)
52 .help("search remote repositories for matching strings"),
57 .conflicts_with("search")
59 .action(ArgAction
::SetTrue
)
60 .help("view package information"),
65 .required_unless_present("search")
67 .multiple_values(true),
72 match matches
.subcommand() {
73 Some(("sync", sync_matches
)) => {
74 if sync_matches
.contains_id("search") {
75 let packages
: Vec
<_
> = sync_matches
76 .get_many
::<String
>("search")
77 .expect("contains_id")
80 let values
= packages
.join(", ");
81 println
!("Searching for {}...", values
);
85 let packages
: Vec
<_
> = sync_matches
86 .get_many
::<String
>("package")
90 let values
= packages
.join(", ");
93 .get_one
::<bool
>("info")
94 .expect("defaulted by clap")
96 println
!("Retrieving info for {}...", values
);
98 println
!("Installing {}...", values
);
101 Some(("query", query_matches
)) => {
102 if let Some(packages
) = query_matches
.get_many
::<String
>("info") {
103 let comma_sep
= packages
.map(|s
| s
.as_str()).collect
::<Vec
<_
>>().join(", ");
104 println
!("Retrieving info for {}...", comma_sep
);
105 } else if let Some(queries
) = query_matches
.get_many
::<String
>("search") {
106 let comma_sep
= queries
.map(|s
| s
.as_str()).collect
::<Vec
<_
>>().join(", ");
107 println
!("Searching Locally for {}...", comma_sep
);
109 println
!("Displaying all locally installed packages...");
112 _
=> unreachable
!(), // If all subcommands are defined above, anything else is unreachable