2022-06-10 01:03:28 +00:00
|
|
|
use clap::{Arg, ArgAction, Command};
|
2020-06-13 16:28:10 +00:00
|
|
|
|
|
|
|
fn main() {
|
2022-02-12 03:48:29 +00:00
|
|
|
let matches = Command::new("pacman")
|
2020-06-13 16:28:10 +00:00
|
|
|
.about("package manager utility")
|
|
|
|
.version("5.2.1")
|
2022-02-11 20:40:04 +00:00
|
|
|
.subcommand_required(true)
|
|
|
|
.arg_required_else_help(true)
|
2020-06-13 16:28:10 +00:00
|
|
|
.author("Pacman Development Team")
|
|
|
|
// Query subcommand
|
|
|
|
//
|
|
|
|
// Only a few of its arguments are implemented below.
|
|
|
|
.subcommand(
|
2022-02-12 03:48:29 +00:00
|
|
|
Command::new("query")
|
2020-06-16 01:52:36 +00:00
|
|
|
.short_flag('Q')
|
|
|
|
.long_flag("query")
|
2020-06-13 16:28:10 +00:00
|
|
|
.about("Query the package database.")
|
|
|
|
.arg(
|
|
|
|
Arg::new("search")
|
|
|
|
.short('s')
|
|
|
|
.long("search")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("search locally installed packages for matching strings")
|
2020-07-08 01:26:38 +00:00
|
|
|
.conflicts_with("info")
|
2022-07-26 00:17:01 +00:00
|
|
|
.action(ArgAction::Set)
|
2022-08-03 16:20:07 +00:00
|
|
|
.num_args(1..),
|
2020-06-13 16:28:10 +00:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::new("info")
|
|
|
|
.long("info")
|
|
|
|
.short('i')
|
2020-07-08 01:26:38 +00:00
|
|
|
.conflicts_with("search")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("view package information")
|
2022-07-26 00:17:01 +00:00
|
|
|
.action(ArgAction::Set)
|
2022-08-03 16:20:07 +00:00
|
|
|
.num_args(1..),
|
2020-06-13 16:28:10 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
// Sync subcommand
|
|
|
|
//
|
|
|
|
// Only a few of its arguments are implemented below.
|
|
|
|
.subcommand(
|
2022-02-12 03:48:29 +00:00
|
|
|
Command::new("sync")
|
2020-06-16 01:52:36 +00:00
|
|
|
.short_flag('S')
|
|
|
|
.long_flag("sync")
|
2020-06-13 16:28:10 +00:00
|
|
|
.about("Synchronize packages.")
|
|
|
|
.arg(
|
|
|
|
Arg::new("search")
|
|
|
|
.short('s')
|
|
|
|
.long("search")
|
2020-07-08 01:26:38 +00:00
|
|
|
.conflicts_with("info")
|
2022-07-26 00:17:01 +00:00
|
|
|
.action(ArgAction::Set)
|
2022-08-03 16:20:07 +00:00
|
|
|
.num_args(1..)
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("search remote repositories for matching strings"),
|
2020-06-13 16:28:10 +00:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::new("info")
|
|
|
|
.long("info")
|
2020-07-08 01:26:38 +00:00
|
|
|
.conflicts_with("search")
|
2020-06-13 16:28:10 +00:00
|
|
|
.short('i')
|
2022-06-10 01:03:28 +00:00
|
|
|
.action(ArgAction::SetTrue)
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("view package information"),
|
2020-06-13 16:28:10 +00:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::new("package")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("packages")
|
2020-08-15 17:11:50 +00:00
|
|
|
.required_unless_present("search")
|
2022-07-26 00:17:01 +00:00
|
|
|
.action(ArgAction::Set)
|
2022-08-03 16:20:07 +00:00
|
|
|
.num_args(1..),
|
2020-06-13 16:28:10 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
.get_matches();
|
|
|
|
|
|
|
|
match matches.subcommand() {
|
2020-08-05 12:36:02 +00:00
|
|
|
Some(("sync", sync_matches)) => {
|
2022-06-10 01:03:28 +00:00
|
|
|
if sync_matches.contains_id("search") {
|
2022-05-23 15:50:11 +00:00
|
|
|
let packages: Vec<_> = sync_matches
|
|
|
|
.get_many::<String>("search")
|
2022-06-10 01:03:28 +00:00
|
|
|
.expect("contains_id")
|
2022-05-23 15:50:11 +00:00
|
|
|
.map(|s| s.as_str())
|
|
|
|
.collect();
|
2020-07-08 01:26:38 +00:00
|
|
|
let values = packages.join(", ");
|
|
|
|
println!("Searching for {}...", values);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-23 15:50:11 +00:00
|
|
|
let packages: Vec<_> = sync_matches
|
|
|
|
.get_many::<String>("package")
|
|
|
|
.expect("is present")
|
|
|
|
.map(|s| s.as_str())
|
|
|
|
.collect();
|
2020-07-08 01:26:38 +00:00
|
|
|
let values = packages.join(", ");
|
|
|
|
|
2022-09-02 00:40:56 +00:00
|
|
|
if sync_matches.get_flag("info") {
|
2020-07-08 01:26:38 +00:00
|
|
|
println!("Retrieving info for {}...", values);
|
2020-06-13 16:28:10 +00:00
|
|
|
} else {
|
2020-07-08 01:26:38 +00:00
|
|
|
println!("Installing {}...", values);
|
2020-06-13 16:28:10 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-05 12:36:02 +00:00
|
|
|
Some(("query", query_matches)) => {
|
2022-05-25 15:46:42 +00:00
|
|
|
if let Some(packages) = query_matches.get_many::<String>("info") {
|
2022-05-23 15:50:11 +00:00
|
|
|
let comma_sep = packages.map(|s| s.as_str()).collect::<Vec<_>>().join(", ");
|
2020-06-17 00:01:19 +00:00
|
|
|
println!("Retrieving info for {}...", comma_sep);
|
2022-05-25 15:46:42 +00:00
|
|
|
} else if let Some(queries) = query_matches.get_many::<String>("search") {
|
2022-05-23 15:50:11 +00:00
|
|
|
let comma_sep = queries.map(|s| s.as_str()).collect::<Vec<_>>().join(", ");
|
2020-06-17 00:01:19 +00:00
|
|
|
println!("Searching Locally for {}...", comma_sep);
|
2020-06-13 16:28:10 +00:00
|
|
|
} else {
|
|
|
|
println!("Displaying all locally installed packages...");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => unreachable!(), // If all subcommands are defined above, anything else is unreachable
|
|
|
|
}
|
|
|
|
}
|