Skip to content

Commit

Permalink
Added the ronin-listener completion command (closes #8).
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Jan 4, 2024
1 parent c9c03f1 commit 761f012
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ platform :jruby do
end

# Ronin dependencies
gem 'ronin-core', '~> 0.1', github: 'ronin-rb/ronin-core',
gem 'ronin-core', '~> 0.2', github: 'ronin-rb/ronin-core',
branch: '0.2.0'
gem 'ronin-listener-dns', '~> 0.1', github: 'ronin-rb/ronin-listener-dns',
branch: 'main'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ ronin-listener new http file.rb
* [Ruby] >= 3.0.0
* [ronin-listener-dns] ~> 0.1
* [ronin-listener-http] ~> 0.1
* [ronin-core] ~> 0.1
* [ronin-core] ~> 0.2

## Install

Expand Down
3 changes: 2 additions & 1 deletion gemspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ metadata:
generated_files:
- data/completions/ronin-listener
- man/ronin-listener.1
- man/ronin-listener-completion.1
- man/ronin-listener-dns.1
- man/ronin-listener-http.1
- man/ronin-listener-new.1
Expand All @@ -32,7 +33,7 @@ dependencies:
# Ronin dependencies:
ronin-listener-dns: ~> 0.1
ronin-listener-http: ~> 0.1
ronin-core: ~> 0.1
ronin-core: ~> 0.2

development_dependencies:
bundler: ~> 2.0
63 changes: 63 additions & 0 deletions lib/ronin/listener/cli/commands/completion.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# frozen_string_literal: true
#
# ronin-listener - A Ruby CLI utility for receiving exfiltrated data.
#
# Copyright (c) 2023 Hal Brodigan (postmodern.mod3@gmail.com)
#
# ronin-listener 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-listener 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-listener. If not, see <https://www.gnu.org/licenses/>.
#

require 'ronin/listener/root'
require 'ronin/core/cli/completion_command'

module Ronin
module Listener
class CLI
module Commands
#
# Manages the shell completion rules for `ronin-listener`.
#
# ## Usage
#
# ronin-listener 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-listener completion --print
# ronin-listener completion --install
# ronin-listener completion --uninstall
#
# @since 0.2.0
#
class Completion < Core::CLI::CompletionCommand

completion_file File.join(ROOT,'data','completions','ronin-listener')

man_dir File.join(ROOT,'man')
man_page 'ronin-listener-completion.1'

description 'Manages the shell completion rules for ronin-listener'

end
end
end
end
end
78 changes: 78 additions & 0 deletions man/ronin-listener-completion.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# ronin-listener-completion 1 "2024-01-01" Ronin Repos "User Manuals"

## NAME

ronin-listener-completion - Manages shell completion rules for `ronin-listener`

## SYNOPSIS

`ronin-listener completion` [*options*]

## DESCRIPTION

The `ronin-listener completion` command can print, install, or uninstall shell
completion rules for the `ronin-listener` 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-listener` 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-listener completion --print`
: Prints the shell completion rules instead of installing them.

`ronin-listener completion --install`
: Installs the shell completion rules for `ronin-listener`.

`ronin-listener completion --uninstall`
: Uninstalls the shell completion rules for `ronin-listener`.

## AUTHOR

Postmodern <postmodern.mod3@gmail.com>

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/listener/cli/commands/completion'
require_relative 'man_page_example'

describe Ronin::Listener::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::Listener::ROOT,'data','completions','ronin-listener')
)
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 761f012

Please sign in to comment.