diff --git a/README.md b/README.md index 0c24ced8..fdf1883c 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ Arguments: [ARGS ...] Additional arguments for the command Commands: + completion diff help html diff --git a/gemspec.yml b/gemspec.yml index 392275f9..efd4ffd0 100644 --- a/gemspec.yml +++ b/gemspec.yml @@ -23,6 +23,7 @@ generated_files: - data/completions/ronin-web - man/ronin-web.1 - man/ronin-web-browser.1 + - man/ronin-web-completion.1 - man/ronin-web-diff.1 - man/ronin-web-html.1 - man/ronin-web-irb.1 diff --git a/lib/ronin/web/cli/commands/completion.rb b/lib/ronin/web/cli/commands/completion.rb new file mode 100644 index 00000000..c74c4a13 --- /dev/null +++ b/lib/ronin/web/cli/commands/completion.rb @@ -0,0 +1,63 @@ +# frozen_string_literal: true +# +# ronin-web - A collection of useful web helper methods and commands. +# +# Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com) +# +# ronin-web is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ronin-web 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ronin-web. If not, see . +# + +require 'ronin/web/root' +require 'ronin/core/cli/completion_command' + +module Ronin + module Web + class CLI + module Commands + # + # Manages the shell completion rules for `ronin-web`. + # + # ## Usage + # + # ronin-web 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-web completion --print + # ronin-web completion --install + # ronin-web completion --uninstall + # + # @since 2.0.0 + # + class Completion < Core::CLI::CompletionCommand + + completion_file File.join(ROOT,'data','completions','ronin-web') + + man_dir File.join(ROOT,'man') + man_page 'ronin-web-completion.1' + + description 'Manages the shell completion rules for ronin-web' + + end + end + end + end +end diff --git a/man/ronin-web-completion.1.md b/man/ronin-web-completion.1.md new file mode 100644 index 00000000..67742223 --- /dev/null +++ b/man/ronin-web-completion.1.md @@ -0,0 +1,78 @@ +# ronin-web-completion 1 "2024-01-01" Ronin Repos "User Manuals" + +## NAME + +ronin-web-completion - Manages shell completion rules for `ronin-web` + +## SYNOPSIS + +`ronin-web completion` [*options*] + +## DESCRIPTION + +The `ronin-web completion` command can print, install, or uninstall shell +completion rules for the `ronin-web` 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-web` 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-web completion --print` +: Prints the shell completion rules instead of installing them. + +`ronin-web completion --install` +: Installs the shell completion rules for `ronin-web`. + +`ronin-web completion --uninstall` +: Uninstalls the shell completion rules for `ronin-web`. + +## AUTHOR + +Postmodern + diff --git a/man/ronin-web.1.md b/man/ronin-web.1.md index 78525ae7..fb20321b 100644 --- a/man/ronin-web.1.md +++ b/man/ronin-web.1.md @@ -30,6 +30,9 @@ A collection of useful web commands. `browser` : Automates a web browser. +`completion` +: Manages the shell completion rules for `ronin-web`. + `diff` : Diffs two web pages. @@ -75,4 +78,4 @@ Postmodern ## SEE ALSO -[ronin-web-browser](ronin-web-browser.1.md) [ronin-web-diff](ronin-web-diff.1.md) [ronin-web-html](ronin-web-html.1.md) [ronin-web-irb](ronin-web-irb.1.md) [ronin-web-new](ronin-web-new.1.md) [ronin-web-reverse-proxy](ronin-web-reverse-proxy.1.md) [ronin-web-screenshot](ronin-web-screenshot.1.md) [ronin-web-server](ronin-web-server.1.md) [ronin-web-session-cookie](ronin-web-session-cookie.1.md) [ronin-web-spider](ronin-web-spider.1.md) [ronin-web-user-agent](ronin-web-user-agent.1.md) [ronin-web-wordlist](ronin-web-wordlist.1.md) [ronin-web-xml](ronin-web-xml.1.md) +[ronin-web-browser](ronin-web-browser.1.md) [ronin-web-completion](ronin-web-completion.1.md) [ronin-web-diff](ronin-web-diff.1.md) [ronin-web-html](ronin-web-html.1.md) [ronin-web-irb](ronin-web-irb.1.md) [ronin-web-new](ronin-web-new.1.md) [ronin-web-reverse-proxy](ronin-web-reverse-proxy.1.md) [ronin-web-screenshot](ronin-web-screenshot.1.md) [ronin-web-server](ronin-web-server.1.md) [ronin-web-session-cookie](ronin-web-session-cookie.1.md) [ronin-web-spider](ronin-web-spider.1.md) [ronin-web-user-agent](ronin-web-user-agent.1.md) [ronin-web-wordlist](ronin-web-wordlist.1.md) [ronin-web-xml](ronin-web-xml.1.md) diff --git a/spec/cli/commands/completion_spec.rb b/spec/cli/commands/completion_spec.rb new file mode 100644 index 00000000..814889ad --- /dev/null +++ b/spec/cli/commands/completion_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper' +require 'ronin/web/cli/commands/completion' +require_relative 'man_page_example' + +describe Ronin::Web::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::Web::ROOT,'data','completions','ronin-web') + ) + 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