rework argument parser

This commit is contained in:
steven-omaha
2023-02-18 19:01:05 +01:00
parent e1ffdc26f7
commit cec0fa8726
2 changed files with 68 additions and 53 deletions
+2
View File
@@ -4,3 +4,5 @@
- create an outer error type for main - create an outer error type for main
- change version names (1.0.0-beta.10) - change version names (1.0.0-beta.10)
- make table use section header with brackets - make table use section header with brackets
- tutorial
- remove "Arch" references
+51 -38
View File
@@ -8,27 +8,37 @@ use crate::action::*;
use crate::core::get_version_string; use crate::core::get_version_string;
fn get_arg_parser() -> Command { fn get_arg_parser() -> Command {
let package_cmd = get_package_cmd();
let group_cmd = get_group_cmd();
let version_cmd = Command::new(VERSION).about("show version info");
Command::new("pacdef") Command::new("pacdef")
.about("declarative package manager for Arch Linux") .about("declarative package manager for Linux")
.version(get_version_string()) .version(get_version_string())
.subcommand_required(true) .subcommand_required(true)
.arg_required_else_help(true) .arg_required_else_help(true)
.subcommand(Command::new(CLEAN).about("remove unmanaged packages")) .subcommands([package_cmd, group_cmd, version_cmd])
.subcommand( }
Command::new(EDIT)
fn get_group_cmd() -> Command {
let remove = Command::new(REMOVE)
.about("remove one or more previously imported groups")
.arg_required_else_help(true)
.arg(Arg::new("groups").num_args(1..));
let edit = Command::new(EDIT)
.about("edit one or more existing group files") .about("edit one or more existing group files")
.arg_required_else_help(true) .arg_required_else_help(true)
.arg(Arg::new("group").num_args(1..)), .arg(Arg::new("group").num_args(1..));
)
.subcommand(Command::new(GROUPS).about("show names of imported groups")) let list = Command::new(GROUPS).about("list names of imported groups");
.subcommand(
Command::new(IMPORT) let import = Command::new(IMPORT)
.about("import one or more group files") .about("import one or more group files")
.arg_required_else_help(true) .arg_required_else_help(true)
.arg(Arg::new("files").num_args(1..)), .arg(Arg::new("files").num_args(1..));
)
.subcommand( let new = Command::new(NEW)
Command::new(NEW)
.about("create new group files") .about("create new group files")
.arg_required_else_help(true) .arg_required_else_help(true)
.arg( .arg(
@@ -38,33 +48,36 @@ fn get_arg_parser() -> Command {
.help("edit the new group files after creation") .help("edit the new group files after creation")
.action(clap::ArgAction::SetTrue), .action(clap::ArgAction::SetTrue),
) )
.arg(Arg::new("groups").num_args(1..)), .arg(Arg::new("groups").num_args(1..));
)
.subcommand( let show = Command::new(SHOW)
Command::new(REMOVE)
.about("remove one or more previously imported groups")
.arg_required_else_help(true)
.arg(Arg::new("groups").num_args(1..)),
)
.subcommand(Command::new(REVIEW).about("review unmanaged packages"))
.subcommand(
Command::new(SEARCH)
.about("search for packages which match a provided string literal or regex")
.arg_required_else_help(true)
.arg(Arg::new("string")),
)
.subcommand(
Command::new(SHOW)
.about("show packages under an imported group") .about("show packages under an imported group")
.arg_required_else_help(true) .arg_required_else_help(true)
.arg(Arg::new("group").num_args(1..)), .arg(Arg::new("group").num_args(1..));
)
.subcommand(Command::new(SYNC).about("install packages from all imported groups")) Command::new("group")
.subcommand( .arg_required_else_help(true)
Command::new(UNMANAGED) .about("TODO????")
.about("show explicitly installed packages not managed by pacdef"), .subcommand_required(true)
) .subcommands([edit, import, list, new, remove, show])
.subcommand(Command::new(VERSION).about("show version info")) }
fn get_package_cmd() -> Command {
let sync = Command::new(SYNC).about("install packages from all imported groups");
let clean = Command::new(CLEAN).about("remove unmanaged packages");
let unmanaged =
Command::new(UNMANAGED).about("show explicitly installed packages not managed by pacdef");
let review = Command::new(REVIEW).about("review unmanaged packages");
let search = Command::new(SEARCH)
.about("search for packages which match a provided string literal or regex")
.arg_required_else_help(true)
.arg(Arg::new("string"));
Command::new("package")
.arg_required_else_help(true)
.about("TODO????")
.subcommand_required(true)
.subcommands([clean, review, unmanaged, search, sync])
} }
/// Get and parse the CLI arguments. /// Get and parse the CLI arguments.