Skip to content

Commit 7755a27

Browse files
committed
Added the ronin-web completion command (closes #89).
1 parent aaa5993 commit 7755a27

File tree

6 files changed

+169
-1
lines changed

6 files changed

+169
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Arguments:
4545
[ARGS ...] Additional arguments for the command
4646
4747
Commands:
48+
completion
4849
diff
4950
help
5051
html

gemspec.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ generated_files:
2323
- data/completions/ronin-web
2424
- man/ronin-web.1
2525
- man/ronin-web-browser.1
26+
- man/ronin-web-completion.1
2627
- man/ronin-web-diff.1
2728
- man/ronin-web-html.1
2829
- man/ronin-web-irb.1
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# frozen_string_literal: true
2+
#
3+
# ronin-web - A collection of useful web helper methods and commands.
4+
#
5+
# Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
6+
#
7+
# ronin-web is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# ronin-web is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with ronin-web. If not, see <https://www.gnu.org/licenses/>.
19+
#
20+
21+
require 'ronin/web/root'
22+
require 'ronin/core/cli/completion_command'
23+
24+
module Ronin
25+
module Web
26+
class CLI
27+
module Commands
28+
#
29+
# Manages the shell completion rules for `ronin-web`.
30+
#
31+
# ## Usage
32+
#
33+
# ronin-web completion [options]
34+
#
35+
# ## Options
36+
#
37+
# --print Prints the shell completion file
38+
# --install Installs the shell completion file
39+
# --uninstall Uninstalls the shell completion file
40+
# -h, --help Print help information
41+
#
42+
# ## Examples
43+
#
44+
# ronin-web completion --print
45+
# ronin-web completion --install
46+
# ronin-web completion --uninstall
47+
#
48+
# @since 2.0.0
49+
#
50+
class Completion < Core::CLI::CompletionCommand
51+
52+
completion_file File.join(ROOT,'data','completions','ronin-web')
53+
54+
man_dir File.join(ROOT,'man')
55+
man_page 'ronin-web-completion.1'
56+
57+
description 'Manages the shell completion rules for ronin-web'
58+
59+
end
60+
end
61+
end
62+
end
63+
end

man/ronin-web-completion.1.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# ronin-web-completion 1 "2024-01-01" Ronin Web "User Manuals"
2+
3+
## NAME
4+
5+
ronin-web-completion - Manages shell completion rules for `ronin-web`
6+
7+
## SYNOPSIS
8+
9+
`ronin-web completion` [*options*]
10+
11+
## DESCRIPTION
12+
13+
The `ronin-web completion` command can print, install, or uninstall shell
14+
completion rules for the `ronin-web` command.
15+
16+
Supports installing completion rules for Bash or Zsh shells.
17+
Completion rules for the Fish shell is currently not supported.
18+
19+
### ZSH SUPPORT
20+
21+
Zsh users will have to add the following lines to their `~/.zshrc` file in
22+
order to enable Zsh's Bash completion compatibility layer:
23+
24+
autoload -Uz +X compinit && compinit
25+
autoload -Uz +X bashcompinit && bashcompinit
26+
27+
## OPTIONS
28+
29+
`--print`
30+
: Prints the shell completion file.
31+
32+
`--install`
33+
: Installs the shell completion file.
34+
35+
`--uninstall`
36+
: Uninstalls the shell completion file.
37+
38+
`-h`, `--help`
39+
: Prints help information.
40+
41+
## ENVIRONMENT
42+
43+
*PREFIX*
44+
: Specifies the root prefix for the file system.
45+
46+
*HOME*
47+
: Specifies the home directory of the user. Ronin will search for the
48+
`~/.cache/ronin-web` cache directory within the home directory.
49+
50+
*XDG_DATA_HOME*
51+
: Specifies the data directory to use. Defaults to `$HOME/.local/share`.
52+
53+
## FILES
54+
55+
`~/.local/share/bash-completion/completions/`
56+
: The user-local installation directory for Bash completion files.
57+
58+
`/usr/local/share/bash-completion/completions/`
59+
: The system-wide installation directory for Bash completions files.
60+
61+
`/usr/local/share/zsh/site-functions/`
62+
: The installation directory for Zsh completion files.
63+
64+
## EXAMPLES
65+
66+
`ronin-web completion --print`
67+
: Prints the shell completion rules instead of installing them.
68+
69+
`ronin-web completion --install`
70+
: Installs the shell completion rules for `ronin-web`.
71+
72+
`ronin-web completion --uninstall`
73+
: Uninstalls the shell completion rules for `ronin-web`.
74+
75+
## AUTHOR
76+
77+
Postmodern <postmodern.mod3@gmail.com>
78+

man/ronin-web.1.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ A collection of useful web commands.
3030
`browser`
3131
: Automates a web browser.
3232

33+
`completion`
34+
: Manages the shell completion rules for `ronin-web`.
35+
3336
`diff`
3437
: Diffs two web pages.
3538

@@ -75,4 +78,4 @@ Postmodern <postmodern.mod3@gmail.com>
7578

7679
## SEE ALSO
7780

78-
[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)
81+
[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)

spec/cli/commands/completion_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
require 'spec_helper'
2+
require 'ronin/web/cli/commands/completion'
3+
require_relative 'man_page_example'
4+
5+
describe Ronin::Web::CLI::Commands::Completion do
6+
it "must inherit from Ronin::Core::CLI::CompletionCommand" do
7+
expect(described_class).to be < Ronin::Core::CLI::CompletionCommand
8+
end
9+
10+
it "must set completion_file" do
11+
expect(described_class.completion_file).to eq(
12+
File.join(Ronin::Web::ROOT,'data','completions','ronin-web')
13+
)
14+
end
15+
16+
it "must set man_dir" do
17+
expect(described_class.man_dir).to_not be(nil)
18+
expect(File.directory?(described_class.man_dir)).to be(true)
19+
end
20+
21+
include_examples "man_page"
22+
end

0 commit comments

Comments
 (0)