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
- change version names (1.0.0-beta.10)
- 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;
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")
.about("declarative package manager for Arch Linux")
.about("declarative package manager for Linux")
.version(get_version_string())
.subcommand_required(true)
.arg_required_else_help(true)
.subcommand(Command::new(CLEAN).about("remove unmanaged packages"))
.subcommand(
Command::new(EDIT)
.about("edit one or more existing group files")
.arg_required_else_help(true)
.arg(Arg::new("group").num_args(1..)),
.subcommands([package_cmd, group_cmd, version_cmd])
}
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")
.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"))
.subcommand(
Command::new(IMPORT)
.about("import one or more group files")
.arg_required_else_help(true)
.arg(Arg::new("files").num_args(1..)),
)
.subcommand(
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),
)
.arg(Arg::new("groups").num_args(1..)),
)
.subcommand(
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")
.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"))
.arg(Arg::new("groups").num_args(1..));
let show = Command::new(SHOW)
.about("show packages under an imported group")
.arg_required_else_help(true)
.arg(Arg::new("group").num_args(1..));
Command::new("group")
.arg_required_else_help(true)
.about("TODO????")
.subcommand_required(true)
.subcommands([edit, import, list, new, remove, show])
}
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.