From 0698dbb2110348f529e62d4f4e1562dc6540701b Mon Sep 17 00:00:00 2001 From: Postmodern Date: Thu, 4 Jan 2024 04:02:36 -0800 Subject: [PATCH] Added the `ronin-exploits completion` command (closes #118). --- Gemfile | 6 +- README.md | 3 +- gemspec.yml | 3 +- lib/ronin/exploits/cli/commands/completion.rb | 64 +++++++++++++++ man/ronin-exploits-completion.1.md | 78 +++++++++++++++++++ spec/cli/commands/completion_spec.rb | 22 ++++++ 6 files changed, 171 insertions(+), 5 deletions(-) create mode 100644 lib/ronin/exploits/cli/commands/completion.rb create mode 100644 man/ronin-exploits-completion.1.md create mode 100644 spec/cli/commands/completion_spec.rb diff --git a/Gemfile b/Gemfile index 1b9ee34e..e86af201 100644 --- a/Gemfile +++ b/Gemfile @@ -11,7 +11,7 @@ end # gem 'fake_io', '~> 0.1', github: 'postmodern/fake_io.rb', # branch: 'main' -# gem 'command_kit', '~> 0.4', github: 'postmodern/command_kit.rb', +# gem 'command_kit', '~> 0.5', github: 'postmodern/command_kit.rb', # branch: 'main' # Ronin dependencies @@ -23,8 +23,8 @@ end # branch: 'main' # gem 'ronin-post_ex', '~> 0.1', github: 'ronin-rb/ronin-post_ex', # branch: 'main' -# gem 'ronin-core', '~> 0.1', github: 'ronin-rb/ronin-core', -# branch: 'main' +gem 'ronin-core', '~> 0.2', github: 'ronin-rb/ronin-core', + branch: '0.2.0' # gem 'ronin-repos', '~> 0.1', github: 'ronin-rb/ronin-repos', # branch: 'main' # gem 'ronin-code-asm', '~> 1.0', github: 'ronin-rb/ronin-code-asm', diff --git a/README.md b/README.md index e539b824..4cfcf6c9 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,7 @@ Arguments: [ARGS ...] Additional arguments for the command Commands: + completion help irb list, ls @@ -410,7 +411,7 @@ For real-world example ronin exploits, see the [example-exploits] repository. * [uri-query_params] ~> 0.6 * [ronin-support] ~> 1.0 * [ronin-code-sql] ~> 2.0 -* [ronin-core] ~> 0.1 +* [ronin-core] ~> 0.2 * [ronin-repos] ~> 0.1 * [ronin-payloads] ~> 0.1 * [ronin-vulns] ~> 0.1 diff --git a/gemspec.yml b/gemspec.yml index 9a1397b7..050f4f52 100644 --- a/gemspec.yml +++ b/gemspec.yml @@ -26,6 +26,7 @@ metadata: generated_files: - data/completions/ronin-exploits - man/ronin-exploits.1 + - man/ronin-exploits-completion.1 - man/ronin-exploits-irb.1 - man/ronin-exploits-list.1 - man/ronin-exploits-new.1 @@ -40,7 +41,7 @@ dependencies: ronin-payloads: ~> 0.1, >= 0.1.1 ronin-vulns: ~> 0.1, >= 0.1.1 ronin-post_ex: ~> 0.1 - ronin-core: ~> 0.1 + ronin-core: ~> 0.2 ronin-repos: ~> 0.1 development_dependencies: diff --git a/lib/ronin/exploits/cli/commands/completion.rb b/lib/ronin/exploits/cli/commands/completion.rb new file mode 100644 index 00000000..ce743097 --- /dev/null +++ b/lib/ronin/exploits/cli/commands/completion.rb @@ -0,0 +1,64 @@ +# frozen_string_literal: true +# +# ronin-exploits - A Ruby library for ronin-rb that provides exploitation and +# payload crafting functionality. +# +# Copyright (c) 2007-2023 Hal Brodigan (postmodern.mod3 at gmail.com) +# +# ronin-exploits is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ronin-exploits is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with ronin-exploits. If not, see . +# + +require 'ronin/exploits/root' +require 'ronin/core/cli/completion_command' + +module Ronin + module Exploits + class CLI + module Commands + # + # Manages the shell completion rules for `ronin-exploits`. + # + # ## Usage + # + # ronin-exploits completion [options] + # + # ## Options + # + # --print Prints the shell completion file + # --install Installs the shell completion file + # --uninstall Uninstalls the shell completion file + # -h, --help Print help information + # + # ## Examples + # + # ronin-exploits completion --print + # ronin-exploits completion --install + # ronin-exploits completion --uninstall + # + # @since 1.1.0 + # + class Completion < Core::CLI::CompletionCommand + + completion_file File.join(ROOT,'data','completions','ronin-exploits') + + man_dir File.join(ROOT,'man') + man_page 'ronin-exploits-completion.1' + + description 'Manages the shell completion rules for ronin-exploits' + + end + end + end + end +end diff --git a/man/ronin-exploits-completion.1.md b/man/ronin-exploits-completion.1.md new file mode 100644 index 00000000..2de4b9b0 --- /dev/null +++ b/man/ronin-exploits-completion.1.md @@ -0,0 +1,78 @@ +# ronin-exploits-completion 1 "2024-01-01" Ronin Exploits "User Manuals" + +## NAME + +ronin-exploits-completion - Manages shell completion rules for `ronin-exploits` + +## SYNOPSIS + +`ronin-exploits completion` [*options*] + +## DESCRIPTION + +The `ronin-exploits completion` command can print, install, or uninstall shell +completion rules for the `ronin-exploits` command. + +Supports installing completion rules for Bash or Zsh shells. +Completion rules for the Fish shell is currently not supported. + +### ZSH SUPPORT + +Zsh users will have to add the following lines to their `~/.zshrc` file in +order to enable Zsh's Bash completion compatibility layer: + + autoload -Uz +X compinit && compinit + autoload -Uz +X bashcompinit && bashcompinit + +## OPTIONS + +`--print` +: Prints the shell completion file. + +`--install` +: Installs the shell completion file. + +`--uninstall` +: Uninstalls the shell completion file. + +`-h`, `--help` +: Prints help information. + +## ENVIRONMENT + +*PREFIX* +: Specifies the root prefix for the file system. + +*HOME* +: Specifies the home directory of the user. Ronin will search for the + `~/.cache/ronin-exploits` cache directory within the home directory. + +*XDG_DATA_HOME* +: Specifies the data directory to use. Defaults to `$HOME/.local/share`. + +## FILES + +`~/.local/share/bash-completion/completions/` +: The user-local installation directory for Bash completion files. + +`/usr/local/share/bash-completion/completions/` +: The system-wide installation directory for Bash completions files. + +`/usr/local/share/zsh/site-functions/` +: The installation directory for Zsh completion files. + +## EXAMPLES + +`ronin-exploits completion --print` +: Prints the shell completion rules instead of installing them. + +`ronin-exploits completion --install` +: Installs the shell completion rules for `ronin-exploits`. + +`ronin-exploits completion --uninstall` +: Uninstalls the shell completion rules for `ronin-exploits`. + +## AUTHOR + +Postmodern + diff --git a/spec/cli/commands/completion_spec.rb b/spec/cli/commands/completion_spec.rb new file mode 100644 index 00000000..35c8b4a3 --- /dev/null +++ b/spec/cli/commands/completion_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper' +require 'ronin/exploits/cli/commands/completion' +require_relative 'man_page_example' + +describe Ronin::Exploits::CLI::Commands::Completion do + it "must inherit from Ronin::Core::CLI::CompletionCommand" do + expect(described_class).to be < Ronin::Core::CLI::CompletionCommand + end + + it "must set completion_file" do + expect(described_class.completion_file).to eq( + File.join(Ronin::Exploits::ROOT,'data','completions','ronin-exploits') + ) + end + + it "must set man_dir" do + expect(described_class.man_dir).to_not be(nil) + expect(File.directory?(described_class.man_dir)).to be(true) + end + + include_examples "man_page" +end