ronin-core 0.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.github/workflows/ruby.yml +41 -0
  4. data/.gitignore +12 -0
  5. data/.rspec +1 -0
  6. data/.rubocop.yml +160 -0
  7. data/.ruby-version +1 -0
  8. data/.yardopts +1 -0
  9. data/COPYING.txt +165 -0
  10. data/ChangeLog.md +11 -0
  11. data/Gemfile +30 -0
  12. data/README.md +299 -0
  13. data/Rakefile +34 -0
  14. data/examples/ruby_shell.rb +11 -0
  15. data/gemspec.yml +28 -0
  16. data/lib/ronin/core/class_registry.rb +246 -0
  17. data/lib/ronin/core/cli/command.rb +87 -0
  18. data/lib/ronin/core/cli/command_shell/command.rb +110 -0
  19. data/lib/ronin/core/cli/command_shell.rb +345 -0
  20. data/lib/ronin/core/cli/generator/options/author.rb +106 -0
  21. data/lib/ronin/core/cli/generator/options/description.rb +54 -0
  22. data/lib/ronin/core/cli/generator/options/reference.rb +60 -0
  23. data/lib/ronin/core/cli/generator/options/summary.rb +54 -0
  24. data/lib/ronin/core/cli/generator.rb +238 -0
  25. data/lib/ronin/core/cli/logging.rb +59 -0
  26. data/lib/ronin/core/cli/options/param.rb +68 -0
  27. data/lib/ronin/core/cli/options/values/arches.rb +45 -0
  28. data/lib/ronin/core/cli/options/values/oses.rb +32 -0
  29. data/lib/ronin/core/cli/printing/arch.rb +71 -0
  30. data/lib/ronin/core/cli/printing/metadata.rb +113 -0
  31. data/lib/ronin/core/cli/printing/os.rb +54 -0
  32. data/lib/ronin/core/cli/printing/params.rb +69 -0
  33. data/lib/ronin/core/cli/ruby_shell.rb +131 -0
  34. data/lib/ronin/core/cli/shell.rb +186 -0
  35. data/lib/ronin/core/git.rb +73 -0
  36. data/lib/ronin/core/home.rb +86 -0
  37. data/lib/ronin/core/metadata/authors/author.rb +241 -0
  38. data/lib/ronin/core/metadata/authors.rb +120 -0
  39. data/lib/ronin/core/metadata/description.rb +100 -0
  40. data/lib/ronin/core/metadata/id.rb +88 -0
  41. data/lib/ronin/core/metadata/references.rb +87 -0
  42. data/lib/ronin/core/metadata/summary.rb +78 -0
  43. data/lib/ronin/core/metadata/version.rb +74 -0
  44. data/lib/ronin/core/params/exceptions.rb +38 -0
  45. data/lib/ronin/core/params/mixin.rb +317 -0
  46. data/lib/ronin/core/params/param.rb +137 -0
  47. data/lib/ronin/core/params/types/boolean.rb +64 -0
  48. data/lib/ronin/core/params/types/enum.rb +107 -0
  49. data/lib/ronin/core/params/types/float.rb +68 -0
  50. data/lib/ronin/core/params/types/integer.rb +100 -0
  51. data/lib/ronin/core/params/types/numeric.rb +106 -0
  52. data/lib/ronin/core/params/types/regexp.rb +67 -0
  53. data/lib/ronin/core/params/types/string.rb +118 -0
  54. data/lib/ronin/core/params/types/type.rb +54 -0
  55. data/lib/ronin/core/params/types/uri.rb +72 -0
  56. data/lib/ronin/core/params/types.rb +62 -0
  57. data/lib/ronin/core/params.rb +19 -0
  58. data/lib/ronin/core/version.rb +24 -0
  59. data/ronin-core.gemspec +59 -0
  60. data/spec/class_registry_spec.rb +224 -0
  61. data/spec/cli/command_shell/command_spec.rb +113 -0
  62. data/spec/cli/command_shell_spec.rb +1114 -0
  63. data/spec/cli/command_spec.rb +16 -0
  64. data/spec/cli/fixtures/irb_command +8 -0
  65. data/spec/cli/fixtures/template/dir/file1.txt +1 -0
  66. data/spec/cli/fixtures/template/dir/file2.txt +1 -0
  67. data/spec/cli/fixtures/template/file.erb +1 -0
  68. data/spec/cli/fixtures/template/file.txt +1 -0
  69. data/spec/cli/generator/options/author_spec.rb +121 -0
  70. data/spec/cli/generator/options/description_spec.rb +45 -0
  71. data/spec/cli/generator/options/reference_spec.rb +53 -0
  72. data/spec/cli/generator/options/summary_spec.rb +45 -0
  73. data/spec/cli/generator_spec.rb +244 -0
  74. data/spec/cli/logging_spec.rb +95 -0
  75. data/spec/cli/options/param_spec.rb +67 -0
  76. data/spec/cli/options/values/arches_spec.rb +62 -0
  77. data/spec/cli/printing/arch_spec.rb +130 -0
  78. data/spec/cli/printing/metadata_spec.rb +211 -0
  79. data/spec/cli/printing/os_spec.rb +64 -0
  80. data/spec/cli/printing/params_spec.rb +63 -0
  81. data/spec/cli/ruby_shell.rb +99 -0
  82. data/spec/cli/shell_spec.rb +211 -0
  83. data/spec/fixtures/example_class_registry/base_class.rb +9 -0
  84. data/spec/fixtures/example_class_registry/classes/loaded_class.rb +9 -0
  85. data/spec/fixtures/example_class_registry/classes/name_mismatch.rb +9 -0
  86. data/spec/fixtures/example_class_registry/classes/no_module.rb +4 -0
  87. data/spec/fixtures/example_class_registry.rb +8 -0
  88. data/spec/git_spec.rb +58 -0
  89. data/spec/home_spec.rb +64 -0
  90. data/spec/metadata/authors/author_spec.rb +335 -0
  91. data/spec/metadata/authors_spec.rb +126 -0
  92. data/spec/metadata/description_spec.rb +74 -0
  93. data/spec/metadata/id_spec.rb +92 -0
  94. data/spec/metadata/references_spec.rb +100 -0
  95. data/spec/metadata/summary_spec.rb +74 -0
  96. data/spec/metadata/version_spec.rb +72 -0
  97. data/spec/params/mixin_spec.rb +484 -0
  98. data/spec/params/param_spec.rb +164 -0
  99. data/spec/params/types/boolean_spec.rb +56 -0
  100. data/spec/params/types/enum_spec.rb +94 -0
  101. data/spec/params/types/float_spec.rb +107 -0
  102. data/spec/params/types/integer_spec.rb +155 -0
  103. data/spec/params/types/numeric_spec.rb +138 -0
  104. data/spec/params/types/regexp_spec.rb +64 -0
  105. data/spec/params/types/string_spec.rb +174 -0
  106. data/spec/params/types/type_spec.rb +14 -0
  107. data/spec/params/types/uri_spec.rb +62 -0
  108. data/spec/spec_helper.rb +11 -0
  109. metadata +252 -0
@@ -0,0 +1,211 @@
1
+ require 'spec_helper'
2
+ require 'ronin/core/cli/shell'
3
+
4
+ describe Ronin::Core::CLI::Shell do
5
+ describe ".shell_name" do
6
+ subject { shell_class }
7
+
8
+ context "and when shell_name is not set in the shell class" do
9
+ module TestShell
10
+ class ShellWithNoShellName < Ronin::Core::CLI::Shell
11
+ end
12
+ end
13
+
14
+ let(:shell_class) { TestShell::ShellWithNoShellName }
15
+
16
+ it "must default to nil" do
17
+ expect(subject.shell_name).to be(nil)
18
+ end
19
+ end
20
+
21
+ context "and when shell_name is set in the shell class" do
22
+ module TestShell
23
+ class ShellWithShellName < Ronin::Core::CLI::Shell
24
+ shell_name 'test'
25
+ end
26
+ end
27
+
28
+ let(:shell_class) { TestShell::ShellWithShellName }
29
+
30
+ it "must return the set shell_name" do
31
+ expect(subject.shell_name).to eq("test")
32
+ end
33
+ end
34
+
35
+ context "but when the shell_name was set in the superclass" do
36
+ module TestShell
37
+ class ShellThatInheritsItsShellName < ShellWithShellName
38
+ end
39
+ end
40
+
41
+ let(:shell_class) do
42
+ TestShell::ShellThatInheritsItsShellName
43
+ end
44
+
45
+ it "must return the shell_name set in the superclass" do
46
+ expect(subject.shell_name).to eq("test")
47
+ end
48
+
49
+ context "but the shell_name is overridden in the sub-class" do
50
+ module TestShell
51
+ class ShellThatOverridesItsInheritedShellName < ShellWithShellName
52
+ shell_name "test2"
53
+ end
54
+ end
55
+
56
+ let(:shell_class) do
57
+ TestShell::ShellThatOverridesItsInheritedShellName
58
+ end
59
+
60
+ it "must return the shell_name set in the sub-class" do
61
+ expect(subject.shell_name).to eq("test2")
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ describe ".prompt_sigil" do
68
+ subject { shell_class }
69
+
70
+ context "and when prompt_sigil is not set in the shell class" do
71
+ module TestShell
72
+ class ShellWithNoPromptSigil < Ronin::Core::CLI::Shell
73
+ end
74
+ end
75
+
76
+ let(:shell_class) { TestShell::ShellWithNoPromptSigil }
77
+
78
+ it "must default to '>'" do
79
+ expect(subject.prompt_sigil).to eq('>')
80
+ end
81
+ end
82
+
83
+ context "and when prompt_sigil is set in the shell class" do
84
+ module TestShell
85
+ class ShellWithPromptSigil < Ronin::Core::CLI::Shell
86
+ prompt_sigil '$'
87
+ end
88
+ end
89
+
90
+ let(:shell_class) { TestShell::ShellWithPromptSigil }
91
+
92
+ it "must return the set prompt_sigil" do
93
+ expect(subject.prompt_sigil).to eq("$")
94
+ end
95
+ end
96
+
97
+ context "but when the prompt_sigil was set in the superclass" do
98
+ module TestShell
99
+ class ShellThatInheritsItsPromptSigil < ShellWithPromptSigil
100
+ end
101
+ end
102
+
103
+ let(:shell_class) do
104
+ TestShell::ShellThatInheritsItsPromptSigil
105
+ end
106
+
107
+ it "must return the prompt_sigil set in the superclass" do
108
+ expect(subject.prompt_sigil).to eq("$")
109
+ end
110
+
111
+ context "but the prompt_sigil is overridden in the sub-class" do
112
+ module TestShell
113
+ class ShellThatOverridesItsInheritedPromptSigil < ShellWithPromptSigil
114
+ prompt_sigil "#"
115
+ end
116
+ end
117
+
118
+ let(:shell_class) do
119
+ TestShell::ShellThatOverridesItsInheritedPromptSigil
120
+ end
121
+
122
+ it "must return the prompt_sigil set in the sub-class" do
123
+ expect(subject.prompt_sigil).to eq("#")
124
+ end
125
+ end
126
+ end
127
+ end
128
+
129
+ module TestShell
130
+ class TestShell < Ronin::Core::CLI::Shell
131
+ shell_name 'test'
132
+ end
133
+ end
134
+
135
+ let(:shell_class) { TestShell::TestShell }
136
+ subject { shell_class.new }
137
+
138
+ describe "#initialize" do
139
+ context "when no keyword arguments are given" do
140
+ it "must default #shell_name to self.class.shell_name" do
141
+ expect(subject.shell_name).to eq(shell_class.shell_name)
142
+ end
143
+
144
+ it "must default #prompt_sigil to self.class.prompt_sigil" do
145
+ expect(subject.prompt_sigil).to eq(shell_class.prompt_sigil)
146
+ end
147
+ end
148
+
149
+ context "when the shell_name: keyword argument is given" do
150
+ let(:new_shell_name) { 'override' }
151
+
152
+ subject { shell_class.new(shell_name: new_shell_name) }
153
+
154
+ it "must override #shell_name" do
155
+ expect(subject.shell_name).to eq(new_shell_name)
156
+ end
157
+ end
158
+
159
+ context "when the prompt_sigil: keyword argument is given" do
160
+ let(:new_prompt_sigil) { '$' }
161
+
162
+ subject { shell_class.new(prompt_sigil: new_prompt_sigil) }
163
+
164
+ it "must override #prompt_sigil" do
165
+ expect(subject.prompt_sigil).to eq(new_prompt_sigil)
166
+ end
167
+ end
168
+ end
169
+
170
+ describe "#shell_name" do
171
+ it "must return the shell class'es .shell_name" do
172
+ expect(subject.shell_name).to eq(shell_class.shell_name)
173
+ end
174
+ end
175
+
176
+ describe "#prompt_sigil" do
177
+ it "must return the shell class'es .prompt_sigil" do
178
+ expect(subject.prompt_sigil).to eq(shell_class.prompt_sigil)
179
+ end
180
+ end
181
+
182
+ describe "#prompt" do
183
+ let(:stdout) { StringIO.new }
184
+
185
+ subject { shell_class.new(stdout: stdout) }
186
+
187
+ context "when stdout is a TTY" do
188
+ before do
189
+ allow(subject.stdout).to receive(:tty?).and_return(true)
190
+ end
191
+
192
+ let(:red) { CommandKit::Colors::ANSI::RED }
193
+ let(:bright_red) { CommandKit::Colors::ANSI::BRIGHT_RED }
194
+ let(:bold) { CommandKit::Colors::ANSI::BOLD }
195
+ let(:reset_intensity) { CommandKit::Colors::ANSI::RESET_INTENSITY }
196
+ let(:reset_color) { CommandKit::Colors::ANSI::RESET_COLOR }
197
+
198
+ it "must return an ANSI colored prompt" do
199
+ expect(subject.prompt).to eq(
200
+ "#{red}#{subject.shell_name}#{reset_color}#{bold}#{bright_red}>#{reset_color}#{reset_intensity}"
201
+ )
202
+ end
203
+ end
204
+
205
+ context "when stdout is not a TTY" do
206
+ it "must return a plain-text prompt" do
207
+ expect(subject.prompt).to eq("#{subject.shell_name}>")
208
+ end
209
+ end
210
+ end
211
+ end
@@ -0,0 +1,9 @@
1
+ module ExampleClassRegistry
2
+ class BaseClass
3
+
4
+ def self.register(path)
5
+ ExampleClassRegistry.register(path,self)
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require_relative '../base_class'
2
+
3
+ module ExampleClassRegistry
4
+ class LoadedClass < BaseClass
5
+
6
+ register 'loaded_class'
7
+
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require_relative '../base_class'
2
+
3
+ module ExampleClassRegistry
4
+ class LoadedModule < BaseClass
5
+
6
+ register 'different_name'
7
+
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ module ExampleClassRegistry
2
+ class SomeClass
3
+ end
4
+ end
@@ -0,0 +1,8 @@
1
+ require 'ronin/core/class_registry'
2
+
3
+ module ExampleClassRegistry
4
+
5
+ include Ronin::Core::ClassRegistry
6
+ class_dir "#{__dir__}/example_class_registry/classes"
7
+
8
+ end
data/spec/git_spec.rb ADDED
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+ require 'ronin/core/git'
3
+
4
+ describe Ronin::Core::Git do
5
+ describe ".user_name" do
6
+ let(:user_name) { 'Foo Bar' }
7
+
8
+ it "must execute `git config user.name`" do
9
+ expect(subject).to receive(:`).with("git config user.name").and_return("#{user_name}#{$/}")
10
+
11
+ expect(subject.user_name).to eq(user_name)
12
+ end
13
+
14
+ context "when `git config user.name` returns an empty String" do
15
+ it "must return nil" do
16
+ expect(subject).to receive(:`).with("git config user.name").and_return("")
17
+
18
+ expect(subject.user_name).to be(nil)
19
+ end
20
+ end
21
+ end
22
+
23
+ describe ".user_email" do
24
+ let(:user_email) { 'foo@example.com' }
25
+
26
+ it "must execute `git config user.email`" do
27
+ expect(subject).to receive(:`).with("git config user.email").and_return("#{user_email}#{$/}")
28
+
29
+ expect(subject.user_email).to eq(user_email)
30
+ end
31
+
32
+ context "when `git config user.email` returns an empty String" do
33
+ it "must return nil" do
34
+ expect(subject).to receive(:`).with("git config user.email").and_return("")
35
+
36
+ expect(subject.user_email).to be(nil)
37
+ end
38
+ end
39
+ end
40
+
41
+ describe ".github_user" do
42
+ let(:github_user) { 'foo' }
43
+
44
+ it "must execute `git config github.user`" do
45
+ expect(subject).to receive(:`).with("git config github.user").and_return("#{github_user}#{$/}")
46
+
47
+ expect(subject.github_user).to eq(github_user)
48
+ end
49
+
50
+ context "when `git config github.user` returns an empty String" do
51
+ it "must return nil" do
52
+ expect(subject).to receive(:`).with("git config github.user").and_return("")
53
+
54
+ expect(subject.github_user).to be(nil)
55
+ end
56
+ end
57
+ end
58
+ end
data/spec/home_spec.rb ADDED
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+ require 'ronin/core/home'
3
+
4
+ describe Ronin::Core::Home do
5
+ describe "DIR" do
6
+ it "must equal Gem.user_home" do
7
+ expect(subject::DIR).to eq(Gem.user_home)
8
+ end
9
+ end
10
+
11
+ describe "CACHE_DIR" do
12
+ it "must equal ~/.cache" do
13
+ expect(subject::CACHE_DIR).to eq(
14
+ File.join(Gem.user_home,'.cache')
15
+ )
16
+ end
17
+ end
18
+
19
+ describe ".cache_dir" do
20
+ let(:name) { 'foo' }
21
+
22
+ it "must join ~/.cache with the given directory name" do
23
+ expect(subject.cache_dir(name)).to eq(
24
+ File.join(Gem.user_home,'.cache',name)
25
+ )
26
+ end
27
+ end
28
+
29
+ describe "CONFIG_DIR" do
30
+ it "must equal ~/.config" do
31
+ expect(subject::CONFIG_DIR).to eq(
32
+ File.join(Gem.user_home,'.config')
33
+ )
34
+ end
35
+ end
36
+
37
+ describe ".config_dir" do
38
+ let(:name) { 'foo' }
39
+
40
+ it "must join ~/.config with the given directory name" do
41
+ expect(subject.config_dir(name)).to eq(
42
+ File.join(Gem.user_home,'.config',name)
43
+ )
44
+ end
45
+ end
46
+
47
+ describe "LOCAL_SHARE" do
48
+ it "must equal ~/.local/share" do
49
+ expect(subject::LOCAL_SHARE_DIR).to eq(
50
+ File.join(Gem.user_home,'.local','share')
51
+ )
52
+ end
53
+ end
54
+
55
+ describe ".local_share_dir" do
56
+ let(:name) { 'foo' }
57
+
58
+ it "must join ~/.local/share with the given directory name" do
59
+ expect(subject.local_share_dir(name)).to eq(
60
+ File.join(Gem.user_home,'.local','share',name)
61
+ )
62
+ end
63
+ end
64
+ end