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
+3 -1
View File
@@ -3,4 +3,6 @@
- make transition for existing user easier - make transition for existing user easier
- 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
+65 -52
View File
@@ -8,63 +8,76 @@ 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)
.about("edit one or more existing group files") fn get_group_cmd() -> Command {
.arg_required_else_help(true) let remove = Command::new(REMOVE)
.arg(Arg::new("group").num_args(1..)), .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")
.arg_required_else_help(true)
.arg(Arg::new("group").num_args(1..));
let list = Command::new(GROUPS).about("list names of imported groups");
let import = Command::new(IMPORT)
.about("import one or more group files")
.arg_required_else_help(true)
.arg(Arg::new("files").num_args(1..));
let new = Command::new(NEW)
.about("create new group files")
.arg_required_else_help(true)
.arg(
Arg::new("edit")
.short('e')
.long("edit")
.help("edit the new group files after creation")
.action(clap::ArgAction::SetTrue),
) )
.subcommand(Command::new(GROUPS).about("show names of imported groups")) .arg(Arg::new("groups").num_args(1..));
.subcommand(
Command::new(IMPORT) let show = Command::new(SHOW)
.about("import one or more group files") .about("show packages under an imported group")
.arg_required_else_help(true) .arg_required_else_help(true)
.arg(Arg::new("files").num_args(1..)), .arg(Arg::new("group").num_args(1..));
)
.subcommand( Command::new("group")
Command::new(NEW) .arg_required_else_help(true)
.about("create new group files") .about("TODO????")
.arg_required_else_help(true) .subcommand_required(true)
.arg( .subcommands([edit, import, list, new, remove, show])
Arg::new("edit") }
.short('e')
.long("edit") fn get_package_cmd() -> Command {
.help("edit the new group files after creation") let sync = Command::new(SYNC).about("install packages from all imported groups");
.action(clap::ArgAction::SetTrue), let clean = Command::new(CLEAN).about("remove unmanaged packages");
) let unmanaged =
.arg(Arg::new("groups").num_args(1..)), Command::new(UNMANAGED).about("show explicitly installed packages not managed by pacdef");
) let review = Command::new(REVIEW).about("review unmanaged packages");
.subcommand( let search = Command::new(SEARCH)
Command::new(REMOVE) .about("search for packages which match a provided string literal or regex")
.about("remove one or more previously imported groups") .arg_required_else_help(true)
.arg_required_else_help(true) .arg(Arg::new("string"));
.arg(Arg::new("groups").num_args(1..)),
) Command::new("package")
.subcommand(Command::new(REVIEW).about("review unmanaged packages")) .arg_required_else_help(true)
.subcommand( .about("TODO????")
Command::new(SEARCH) .subcommand_required(true)
.about("search for packages which match a provided string literal or regex") .subcommands([clean, review, unmanaged, search, sync])
.arg_required_else_help(true)
.arg(Arg::new("string")),
)
.subcommand(
Command::new(SHOW)
.about("show packages under an imported group")
.arg_required_else_help(true)
.arg(Arg::new("group").num_args(1..)),
)
.subcommand(Command::new(SYNC).about("install packages from all imported groups"))
.subcommand(
Command::new(UNMANAGED)
.about("show explicitly installed packages not managed by pacdef"),
)
.subcommand(Command::new(VERSION).about("show version info"))
} }
/// Get and parse the CLI arguments. /// Get and parse the CLI arguments.