diff --git a/Gemfile b/Gemfile index f7bfc9b..5c965bf 100644 --- a/Gemfile +++ b/Gemfile @@ -8,6 +8,7 @@ gemspec # Needed for the CLI only group :runtime, :cli do gem 'dry-cli', '~> 1.4' # for arg parsing + gem 'dry-cli-completion', '~> 2.0' # for shell completion gem 'paint', '~> 2.3' # for colorized ouput end diff --git a/Gemfile.lock b/Gemfile.lock index b9654df..73f7019 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,10 +3,11 @@ PATH specs: unisec (0.0.8) ctf-party (~> 5.0) - dry-cli (~> 1.0) + dry-cli (~> 1.4) + dry-cli-completion (~> 2.0.0) paint (~> 2.3) twitter_cldr (~> 6.13) - unicode-confusable (~> 1.12) + unicode-confusable (~> 1.13) GEM remote: https://rubygems.org/ @@ -18,7 +19,11 @@ GEM cgi (0.5.1) cldr-plurals-runtime-rb (1.1.0) coderay (1.1.3) + colsole (1.0.1) commonmarker (2.8.2-x86_64-linux) + completely (0.7.5) + colsole (~> 1.0.0) + mister_bin (~> 0.7) concurrent-ruby (1.3.6) ctf-party (5.0.0) base64 (~> 0.2.0) @@ -27,8 +32,12 @@ GEM uri (~> 1.1) date (3.5.1) docopt (0.6.1) + docopt_ng (0.7.1) drb (2.2.3) dry-cli (1.4.1) + dry-cli-completion (2.0.0) + completely (~> 0.7) + dry-cli (~> 1.4) erb (6.0.4) io-console (0.8.2) irb (1.18.0) @@ -45,6 +54,10 @@ GEM prism (~> 1.5) minitest-skip (1.0.0) minitest (~> 6.0) + mister_bin (0.9.0) + colsole (~> 1.0.0) + docopt_ng (~> 0.7.1) + reline (~> 0.6) ostruct (0.6.3) paint (2.3.0) parallel (2.1.0) @@ -112,6 +125,7 @@ DEPENDENCIES commonmarker (~> 2.8) ctf-party (~> 5.0) dry-cli (~> 1.4) + dry-cli-completion (~> 2.0) irb logger minitest (~> 6.0) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 49ec265..8d2435f 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -11,6 +11,7 @@ - New utils method: - `Unisec::Utils::Arguments.to_array_of_sym` - `Unisec::Utils::Arguments.argenc2enc` +- Add shell completion for CLI **Chore** diff --git a/docs/pages/install.md b/docs/pages/install.md index 3cab660..b23556e 100644 --- a/docs/pages/install.md +++ b/docs/pages/install.md @@ -102,3 +102,28 @@ ruby -Ilib -runisec bin/unisec ``` + +## Shell completion + + + +### **zsh** + +Add in `~/.zshrc` + +```bash +source <(unisec completion zsh) +``` + +### **bash** + +Add in `~/.bashrc` + +```bash +# bash 3.0+ +source <(unisec completion bash) +# else +eval "$(unisec completion bash)" +``` + + diff --git a/lib/unisec/cli/cli.rb b/lib/unisec/cli/cli.rb index 9c84ed7..c174990 100644 --- a/lib/unisec/cli/cli.rb +++ b/lib/unisec/cli/cli.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +require 'dry/cli/completion/command' require 'unisec/cli/bidi' require 'unisec/cli/blocks' require 'unisec/cli/confusables' @@ -25,6 +26,7 @@ module Commands register 'blocks invalid', Blocks::Invalid register 'blocks list', Blocks::List register 'blocks search', Blocks::Search + register 'completion', Dry::CLI::Completion::Command[self] register 'confusables list', Confusables::List register 'confusables randomize', Confusables::Randomize register 'dump codepoints integer', Dump::Codepoints::Integer diff --git a/unisec.gemspec b/unisec.gemspec index 8089c9d..09559cd 100644 --- a/unisec.gemspec +++ b/unisec.gemspec @@ -33,8 +33,9 @@ Gem::Specification.new do |s| s.required_ruby_version = ['>= 3.3.0', '< 5.0'] s.add_runtime_dependency('ctf-party', '~> 5.0') # string conversion - s.add_runtime_dependency('dry-cli', '~> 1.0') # CLI + s.add_runtime_dependency('dry-cli', '~> 1.4') # CLI + s.add_runtime_dependency('dry-cli-completion', '~> 2.0.0') # shell completion s.add_runtime_dependency('paint', '~> 2.3') # colorized output s.add_runtime_dependency('twitter_cldr', '~> 6.13') # ICU / CLDR - s.add_runtime_dependency('unicode-confusable', '~> 1.12') # confusable chars + s.add_runtime_dependency('unicode-confusable', '~> 1.13') # confusable chars end