Skip to content

Commit

Permalink
Added the ronin-web completion command (closes #89).
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Jan 4, 2024
1 parent aaa5993 commit f8879ca
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Arguments:
[ARGS ...] Additional arguments for the command
Commands:
completion
diff
help
html
Expand Down
1 change: 1 addition & 0 deletions gemspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
63 changes: 63 additions & 0 deletions lib/ronin/web/cli/commands/completion.rb
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
#

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
78 changes: 78 additions & 0 deletions man/ronin-web-completion.1.md
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>

5 changes: 4 additions & 1 deletion man/ronin-web.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -75,4 +78,4 @@ Postmodern <[email protected]>

## 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)
22 changes: 22 additions & 0 deletions spec/cli/commands/completion_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f8879ca

Please sign in to comment.