Skip to content

Commit

Permalink
Add more basic pattern options to CLI::PatternOptions (#254)
Browse files Browse the repository at this point in the history
Add more basic pattern options to `CLI::PatternOptions` (closes #253)

* `--alpha` - `/[a-zA-Z]+/`
* `--uppercase` - `/[A-Z]+/`
* `--lowercase` - `/[a-z]+/`
* `--alpha-numeric` - `/[0-9a-zA-Z]+/`
* `--hex` - `/[0-9a-fA-F]+/`
* `--uppercase-hex` - `/[0-9A-F]+/`
* `--lowercase-hex` - `/[0-9a-f]+/`
  • Loading branch information
raj921 authored Dec 8, 2024
1 parent da05079 commit 0484108
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/ronin/cli/pattern_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,34 @@ def self.define_numeric_options(command)
desc: 'Searches for all version numbers' do
@pattern = VERSION_NUMBER
end

command.option :alpha, desc: 'Searches for all alphabetic characters' do
@pattern = /[a-zA-Z]+/
end

command.option :uppercase, desc: 'Searches for all uppercase alphabetic characters' do
@pattern = /[A-Z]+/
end

command.option :lowercase, desc: 'Searches for all lowercase alphabetic characters' do
@pattern = /[a-z]+/
end

command.option :alpha_numeric, desc: 'Searches for all alphanumeric characters' do
@pattern = /[0-9a-zA-Z]+/
end

command.option :hex, desc: 'Searches for all hexadecimal characters' do
@pattern = /[0-9a-fA-F]+/
end

command.option :uppercase_hex, desc: 'Searches for all uppercase hexadecimal characters' do
@pattern = /[0-9A-F]+/
end

command.option :lowercase_hex, desc: 'Searches for all lowercase hexadecimal characters' do
@pattern = /[0-9a-f]+/
end
end

#
Expand Down
49 changes: 49 additions & 0 deletions spec/cli/pattern_options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,55 @@ class TestCommand < Ronin::CLI::Command
expect(subject.options[:version_number].desc).to eq('Searches for all version numbers')
end

it "must define a '--alpha' option" do
expect(subject.options[:alpha]).to_not be(nil)
expect(subject.options[:alpha].short).to be(nil)
expect(subject.options[:alpha].value).to be(nil)
expect(subject.options[:alpha].desc).to eq('Searches for all alphabetic characters')
end

it "must define a '--uppercase' option" do
expect(subject.options[:uppercase]).to_not be(nil)
expect(subject.options[:uppercase].short).to be(nil)
expect(subject.options[:uppercase].value).to be(nil)
expect(subject.options[:uppercase].desc).to eq('Searches for all uppercase alphabetic characters')
end

it "must define a '--lowercase' option" do
expect(subject.options[:lowercase]).to_not be(nil)
expect(subject.options[:lowercase].short).to be(nil)
expect(subject.options[:lowercase].value).to be(nil)
expect(subject.options[:lowercase].desc).to eq('Searches for all lowercase alphabetic characters')
end

it "must define a '--alpha-numeric' option" do
expect(subject.options[:alpha_numeric]).to_not be(nil)
expect(subject.options[:alpha_numeric].short).to be(nil)
expect(subject.options[:alpha_numeric].value).to be(nil)
expect(subject.options[:alpha_numeric].desc).to eq('Searches for all alphanumeric characters')
end

it "must define a '--hex' option" do
expect(subject.options[:hex]).to_not be(nil)
expect(subject.options[:hex].short).to be(nil)
expect(subject.options[:hex].value).to be(nil)
expect(subject.options[:hex].desc).to eq('Searches for all hexadecimal characters')
end

it "must define a '--uppercase-hex' option" do
expect(subject.options[:uppercase_hex]).to_not be(nil)
expect(subject.options[:uppercase_hex].short).to be(nil)
expect(subject.options[:uppercase_hex].value).to be(nil)
expect(subject.options[:uppercase_hex].desc).to eq('Searches for all uppercase hexadecimal characters')
end

it "must define a '--lowercase-hex' option" do
expect(subject.options[:lowercase_hex]).to_not be(nil)
expect(subject.options[:lowercase_hex].short).to be(nil)
expect(subject.options[:lowercase_hex].value).to be(nil)
expect(subject.options[:lowercase_hex].desc).to eq('Searches for all lowercase hexadecimal characters')
end

#
# Language pattern options
#
Expand Down

0 comments on commit 0484108

Please sign in to comment.