From 93d4c58a00f50013a416758a8d9adf14e338a6ca Mon Sep 17 00:00:00 2001 From: steven-omaha <35634100+steven-omaha@users.noreply.github.com> Date: Fri, 24 Feb 2023 13:25:33 +0100 Subject: [PATCH] Revert "add auto-generated zsh completion" This reverts commit dca0895b3977f38c8179f501c038908d0710642d. --- Cargo.lock | 10 --- _completion.zsh | 112 +++++++++++++++++++++++++++++++ crates/pacdef_core/Cargo.toml | 1 - crates/pacdef_core/src/action.rs | 1 - crates/pacdef_core/src/args.rs | 11 ++- crates/pacdef_core/src/core.rs | 1 - 6 files changed, 117 insertions(+), 19 deletions(-) create mode 100644 _completion.zsh diff --git a/Cargo.lock b/Cargo.lock index 20d5842..d074894 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -67,15 +67,6 @@ dependencies = [ "termcolor", ] -[[package]] -name = "clap_complete" -version = "4.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0012995dc3a54314f4710f5631d74767e73c534b8757221708303e48eef7a19b" -dependencies = [ - "clap", -] - [[package]] name = "clap_lex" version = "0.3.1" @@ -221,7 +212,6 @@ dependencies = [ "alpm", "anyhow", "clap", - "clap_complete", "const_format", "pacdef_macros", "path-absolutize", diff --git a/_completion.zsh b/_completion.zsh new file mode 100644 index 0000000..a9beae9 --- /dev/null +++ b/_completion.zsh @@ -0,0 +1,112 @@ +#compdef pacdef + +_pacdef() { + integer ret=1 + local line + + if [ -z "${XDG_CONFIG_HOME}" ]; then + GROUPDIR="~/.config/pacdef/groups" + else + GROUPDIR="${XDG_CONFIG_HOME}/pacdef/groups" + fi + + function _subcommands { + local -a subcommands + subcommands=( + 'group:manage groups (alias: g)' + 'package:manage packages (alias: p)' + 'version:show version info (alias: v)' + ) + _describe 'subcommand' subcommands + } + + function _group_actions { + local -a group_actions + group_actions=( + 'edit:edit an imported group file (alias: e)' + 'list:show names of imported groups (alias: l)' + 'import:import a new group file (alias: i)' + 'new:create a new group file (alias: n)' + 'remove:remove a group file (alias: r)' + 'show:show packages under an imported group (alias: s)' + ) + _describe 'group action' group_actions + } + + + function _package_actions { + local -a package_actions + package_actions=( + 'clean:uninstall packages not managed by pacdef (alias: c)' + 'review:review unmanaged packages (alias: r)' + 'search:show the group containing a package (alias: se)' + 'sync:install all packages from imported groups (alias: sy)' + 'unmanaged:show explicitly installed packages not managed by pacdef (alias: u)' + ) + _describe 'package action' package_actions + } + + _arguments -C \ + "1: :_subcommands" \ + "*::arg:->args" \ + && ret=0 + + case $state in + (args) + case $line[1] in + package) + case $line[2] in + search) + _arguments \ + "2:regex:" && ret=0 + ;; + (clean|review|sync|unmanaged|help) + _message "no more arguments" && ret=0 + ;; + *) + _arguments \ + "1: :_package_actions" \ + "*::arg:->args" && ret=0 + ;; + esac + ;; + group) + case $line[2] in + list) + _message "no more arguments" && ret=0 + ;; + (edit|remove|show) + _arguments "*:group file:_files -W '$GROUPDIR'" && ret=0 + + ;; + import) + _arguments "*:new group file(s):_files" && ret=0 + ;; + new) + _arguments \ + {-e,--edit}"[edit group file after creating them]" \ + "*:new group name(s):" \ + && ret=0 + ;; + *) _arguments \ + "1: :_group_actions" \ + "*::arg:->args" && ret=0 + ;; + esac + ;; + version) + _message "no more arguments" && ret=0 + ;; + *) + _message "unknown subcommand" && ret=1 + ;; + esac + ;; + esac + + return ret +} + +_pacdef + + diff --git a/crates/pacdef_core/Cargo.toml b/crates/pacdef_core/Cargo.toml index f0a9a2d..28f9f4b 100644 --- a/crates/pacdef_core/Cargo.toml +++ b/crates/pacdef_core/Cargo.toml @@ -27,4 +27,3 @@ serde_derive = "1.0" serde = "1.0" pacdef_macros = { path = "../pacdef_macros", version = "0.1" } -clap_complete = "4.1.3" diff --git a/crates/pacdef_core/src/action.rs b/crates/pacdef_core/src/action.rs index 74c1c6b..31ce1fa 100644 --- a/crates/pacdef_core/src/action.rs +++ b/crates/pacdef_core/src/action.rs @@ -5,7 +5,6 @@ use pacdef_macros::Action; #[derive(Debug, Action)] pub enum Actions { Clean, - Completion, Edit, Import, List, diff --git a/crates/pacdef_core/src/args.rs b/crates/pacdef_core/src/args.rs index 40fae52..75a2bc8 100644 --- a/crates/pacdef_core/src/args.rs +++ b/crates/pacdef_core/src/args.rs @@ -9,18 +9,17 @@ use crate::core::get_version_string; /// Build the `pacdef` argument parser, with subcommands for `version`, /// `group` and `package`. -pub fn build_cli() -> 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"); - let completion_cmd = Command::new(COMPLETION).about("generate shell completion"); Command::new("pacdef") .about("declarative package manager for Linux") .version(get_version_string()) .subcommand_required(true) .arg_required_else_help(true) - .subcommands([package_cmd, group_cmd, version_cmd, completion_cmd]) + .subcommands([package_cmd, group_cmd, version_cmd]) } /// Build the `pacdef group` subcommand. @@ -68,7 +67,7 @@ fn get_group_cmd() -> Command { Command::new("group") .arg_required_else_help(true) - .about("manage groups") + .about("TODO????") .visible_alias("g") .subcommand_required(true) .subcommands([edit, import, list, new, remove, show]) @@ -96,7 +95,7 @@ fn get_package_cmd() -> Command { Command::new("package") .arg_required_else_help(true) - .about("manage packages") + .about("TODO????") .visible_alias("p") .subcommand_required(true) .subcommands([clean, review, unmanaged, search, sync]) @@ -105,7 +104,7 @@ fn get_package_cmd() -> Command { /// Get and parse the CLI arguments. #[must_use] pub fn get() -> clap::ArgMatches { - build_cli().get_matches() + get_arg_parser().get_matches() } /// For each file argument, return the absolute path to the file. diff --git a/crates/pacdef_core/src/core.rs b/crates/pacdef_core/src/core.rs index 618ca03..76eff96 100644 --- a/crates/pacdef_core/src/core.rs +++ b/crates/pacdef_core/src/core.rs @@ -84,7 +84,6 @@ impl Pacdef { }, Some((VERSION, _)) => Ok(self.show_version()), - Some((COMPLETION, _)) => generate_shell_completion(), Some((_, _)) => panic!("{ACTION_NOT_MATCHED}"), None => unreachable!("{UNREACHABLE_ARM}"),