command_mapper-gen 0.1.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ruby.yml +27 -0
  3. data/.gitignore +10 -0
  4. data/.rspec +1 -0
  5. data/.yardopts +1 -0
  6. data/ChangeLog.md +20 -0
  7. data/Gemfile +17 -0
  8. data/LICENSE.txt +20 -0
  9. data/README.md +145 -0
  10. data/Rakefile +15 -0
  11. data/bin/command_mapper-gen +7 -0
  12. data/commnad_mapper-gen.gemspec +61 -0
  13. data/examples/grep.rb +63 -0
  14. data/gemspec.yml +26 -0
  15. data/lib/command_mapper/gen/arg.rb +43 -0
  16. data/lib/command_mapper/gen/argument.rb +53 -0
  17. data/lib/command_mapper/gen/cli.rb +233 -0
  18. data/lib/command_mapper/gen/command.rb +202 -0
  19. data/lib/command_mapper/gen/exceptions.rb +9 -0
  20. data/lib/command_mapper/gen/option.rb +66 -0
  21. data/lib/command_mapper/gen/option_value.rb +23 -0
  22. data/lib/command_mapper/gen/parsers/common.rb +49 -0
  23. data/lib/command_mapper/gen/parsers/help.rb +351 -0
  24. data/lib/command_mapper/gen/parsers/man.rb +80 -0
  25. data/lib/command_mapper/gen/parsers/options.rb +127 -0
  26. data/lib/command_mapper/gen/parsers/usage.rb +141 -0
  27. data/lib/command_mapper/gen/parsers.rb +2 -0
  28. data/lib/command_mapper/gen/task.rb +90 -0
  29. data/lib/command_mapper/gen/types/enum.rb +30 -0
  30. data/lib/command_mapper/gen/types/key_value.rb +34 -0
  31. data/lib/command_mapper/gen/types/list.rb +34 -0
  32. data/lib/command_mapper/gen/types/map.rb +36 -0
  33. data/lib/command_mapper/gen/types/num.rb +18 -0
  34. data/lib/command_mapper/gen/types/str.rb +48 -0
  35. data/lib/command_mapper/gen/types.rb +6 -0
  36. data/lib/command_mapper/gen/version.rb +6 -0
  37. data/lib/command_mapper/gen.rb +2 -0
  38. data/spec/argument_spec.rb +92 -0
  39. data/spec/cli_spec.rb +269 -0
  40. data/spec/command_spec.rb +316 -0
  41. data/spec/option_spec.rb +85 -0
  42. data/spec/option_value_spec.rb +20 -0
  43. data/spec/parsers/common_spec.rb +616 -0
  44. data/spec/parsers/help_spec.rb +612 -0
  45. data/spec/parsers/man_spec.rb +158 -0
  46. data/spec/parsers/options_spec.rb +802 -0
  47. data/spec/parsers/usage_spec.rb +1175 -0
  48. data/spec/spec_helper.rb +6 -0
  49. data/spec/task_spec.rb +69 -0
  50. data/spec/types/enum_spec.rb +45 -0
  51. data/spec/types/key_value_spec.rb +36 -0
  52. data/spec/types/list_spec.rb +36 -0
  53. data/spec/types/map_spec.rb +48 -0
  54. data/spec/types/str_spec.rb +70 -0
  55. metadata +133 -0
@@ -0,0 +1,6 @@
1
+ require 'rspec'
2
+ require 'command_mapper/gen/version'
3
+ include CommandMapper::Gen
4
+
5
+ require 'simplecov'
6
+ SimpleCov.start
data/spec/task_spec.rb ADDED
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+ require 'command_mapper/gen/task'
3
+
4
+ describe CommandMapper::Gen::Task do
5
+ let(:command_name) { 'grep' }
6
+ let(:output) { '/path/to/output.rb' }
7
+
8
+ subject { described_class.new(command_name,output) }
9
+
10
+ describe "#initialize" do
11
+ it "must set #command_name" do
12
+ expect(subject.command_name).to eq(command_name)
13
+ end
14
+
15
+ it "must set #output" do
16
+ expect(subject.output).to eq(output)
17
+ end
18
+
19
+ context "when the parser: keyword argument is given" do
20
+ let(:parser) { :man }
21
+
22
+ subject { described_class.new(command_name,output, parser: parser) }
23
+
24
+ it "must set #parser" do
25
+ expect(subject.parser).to eq(parser)
26
+ end
27
+ end
28
+
29
+ context "when a block is given" do
30
+ it "must yield the new task and then call #define" do
31
+ yielded_task = nil
32
+
33
+ described_class.new(command_name,output) do |task|
34
+ yielded_task = task
35
+
36
+ expect(task).to receive(:define)
37
+ end
38
+
39
+ expect(yielded_task).to be_kind_of(described_class)
40
+ end
41
+ end
42
+ end
43
+
44
+ describe "#generate" do
45
+ it "must call `sh('command_mapper-gen','--output',output,command_name)`" do
46
+ expect(subject).to receive(:sh).with(
47
+ 'command_mapper-gen', '--output', output, command_name
48
+ )
49
+
50
+ subject.generate
51
+ end
52
+
53
+ context "when #parser is set" do
54
+ let(:parser) { :man }
55
+
56
+ subject { described_class.new(command_name,output, parser: parser) }
57
+
58
+ it "must call `sh('command_mapper-gen','--output',output,'--parser',parser,command_name)`" do
59
+ expect(subject).to receive(:sh).with(
60
+ 'command_mapper-gen', '--output', output,
61
+ '--parser', parser.to_s,
62
+ command_name
63
+ )
64
+
65
+ subject.generate
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+ require 'command_mapper/gen/types/enum'
3
+
4
+ describe CommandMapper::Gen::Types::Enum do
5
+ let(:values) do
6
+ [:foo, :bar, :baz]
7
+ end
8
+
9
+ subject { described_class.new(values) }
10
+
11
+ describe "#initialize" do
12
+ it "must set #values" do
13
+ expect(subject.values).to eq(values)
14
+ end
15
+ end
16
+
17
+ describe "#to_ruby" do
18
+ context "when #map only has one value" do
19
+ let(:value) { :foo }
20
+ let(:values) do
21
+ [value]
22
+ end
23
+
24
+ it "must return 'Enum[value]'" do
25
+ expect(subject.to_ruby).to eq(
26
+ "Enum[#{value.inspect}]"
27
+ )
28
+ end
29
+ end
30
+
31
+ context "when #map has more than one key:value pair" do
32
+ let(:value1) { "foo" }
33
+ let(:value2) { "bar" }
34
+ let(:values) do
35
+ [value1, value2]
36
+ end
37
+
38
+ it "must return 'Enum[value, ...]'" do
39
+ expect(subject.to_ruby).to eq(
40
+ "Enum[#{value1.inspect}, #{value2.inspect}]"
41
+ )
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+ require 'command_mapper/gen/types/key_value'
3
+
4
+ describe CommandMapper::Gen::Types::KeyValue do
5
+ describe "#initialize" do
6
+ it "must default #separator to '='" do
7
+ expect(subject.separator).to eq('=')
8
+ end
9
+
10
+ context "when initialized with the separator: keyword argument" do
11
+ let(:separator) { ':' }
12
+
13
+ subject { described_class.new(separator: separator) }
14
+
15
+ it "must set #separator" do
16
+ expect(subject.separator).to eq(separator)
17
+ end
18
+ end
19
+ end
20
+
21
+ describe "#to_ruby" do
22
+ it "must return 'KeyValue.new()'" do
23
+ expect(subject.to_ruby).to eq("KeyValue.new()")
24
+ end
25
+
26
+ context "when #separator is not '='" do
27
+ let(:separator) { ':' }
28
+
29
+ subject { described_class.new(separator: separator) }
30
+
31
+ it "must return 'KeyValue.new(separator: ...)'" do
32
+ expect(subject.to_ruby).to eq("KeyValue.new(separator: #{separator.inspect})")
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+ require 'command_mapper/gen/types/list'
3
+
4
+ describe CommandMapper::Gen::Types::List do
5
+ describe "#initialize" do
6
+ it "must default #separator to ','" do
7
+ expect(subject.separator).to eq(',')
8
+ end
9
+
10
+ context "when initialized with the separator: keyword argument" do
11
+ let(:separator) { ';' }
12
+
13
+ subject { described_class.new(separator: separator) }
14
+
15
+ it "must set #separator" do
16
+ expect(subject.separator).to eq(separator)
17
+ end
18
+ end
19
+ end
20
+
21
+ describe "#to_ruby" do
22
+ it "must return 'List.new()'" do
23
+ expect(subject.to_ruby).to eq("List.new()")
24
+ end
25
+
26
+ context "when #separator is not ','" do
27
+ let(:separator) { ';' }
28
+
29
+ subject { described_class.new(separator: separator) }
30
+
31
+ it "must return 'List.new(separator: ...)'" do
32
+ expect(subject.to_ruby).to eq("List.new(separator: #{separator.inspect})")
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+ require 'command_mapper/gen/types/map'
3
+
4
+ describe CommandMapper::Gen::Types::Map do
5
+ let(:map) do
6
+ {:foo => "foo", :bar => "bar"}
7
+ end
8
+
9
+ subject { described_class.new(map) }
10
+
11
+ describe "#initialize" do
12
+ it "must set #map" do
13
+ expect(subject.map).to eq(map)
14
+ end
15
+ end
16
+
17
+ describe "#to_ruby" do
18
+ context "when #map only has one key:value pair" do
19
+ let(:key) { :foo }
20
+ let(:value) { "foo" }
21
+ let(:map) do
22
+ {key => value}
23
+ end
24
+
25
+ it "must return 'Map.new(key => value)'" do
26
+ expect(subject.to_ruby).to eq(
27
+ "Map.new(#{key.inspect} => #{value.inspect})"
28
+ )
29
+ end
30
+ end
31
+
32
+ context "when #map has more than one key:value pair" do
33
+ let(:key1) { :foo }
34
+ let(:value1) { "foo" }
35
+ let(:key2) { :bar }
36
+ let(:value2) { "bar" }
37
+ let(:map) do
38
+ {key1 => value1, key2 => value2}
39
+ end
40
+
41
+ it "must return 'Map.new(key => value, ...)'" do
42
+ expect(subject.to_ruby).to eq(
43
+ "Map.new(#{key1.inspect} => #{value1.inspect}, #{key2.inspect} => #{value2.inspect})"
44
+ )
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+ require 'command_mapper/gen/types/str'
3
+
4
+ describe CommandMapper::Gen::Types::Str do
5
+ describe "#initialize" do
6
+ it "must default #allow_empty to nil" do
7
+ expect(subject.allow_empty).to be(nil)
8
+ end
9
+
10
+ it "must default #allow_blank to nil" do
11
+ expect(subject.allow_blank).to be(nil)
12
+ end
13
+
14
+ context "when the allow_empty: keyword is given" do
15
+ let(:allow_empty) { true }
16
+
17
+ subject { described_class.new(allow_empty: allow_empty) }
18
+
19
+ it "must set #allow_empty" do
20
+ expect(subject.allow_empty).to be(allow_empty)
21
+ end
22
+ end
23
+
24
+ context "when the allow_blank: keyword is given" do
25
+ let(:allow_blank) { true }
26
+
27
+ subject { described_class.new(allow_blank: allow_blank) }
28
+
29
+ it "must set #allow_blank" do
30
+ expect(subject.allow_blank).to be(allow_blank)
31
+ end
32
+ end
33
+ end
34
+
35
+ describe "#to_ruby" do
36
+ context "when none of the keywords are set" do
37
+ subject { described_class.new }
38
+
39
+ it "must return nil" do
40
+ expect(subject.to_ruby).to be(nil)
41
+ end
42
+ end
43
+
44
+ context "when only one keyword is set" do
45
+ let(:keyword) { :allow_empty }
46
+ let(:value) { true }
47
+
48
+ subject { described_class.new(**{keyword => value}) }
49
+
50
+ it "must return only that one keyword and it's value" do
51
+ expect(subject.to_ruby).to eq("#{keyword}: #{value.inspect}")
52
+ end
53
+ end
54
+
55
+ context "when more than one keyword is set" do
56
+ let(:allow_empty) { true }
57
+ let(:allow_blank) { true }
58
+
59
+ subject do
60
+ described_class.new(allow_empty: allow_empty, allow_blank: allow_blank)
61
+ end
62
+
63
+ it "must return the set keyword and their values" do
64
+ expect(subject.to_ruby).to eq(
65
+ "allow_empty: #{allow_empty.inspect}, allow_blank: #{allow_blank.inspect}"
66
+ )
67
+ end
68
+ end
69
+ end
70
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: command_mapper-gen
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.pre1
5
+ platform: ruby
6
+ authors:
7
+ - Postmodern
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-11-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: parslet
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ description: command_mapper-gen parses a command's --help output and man-page, then
42
+ generates the command_mapper Ruby class for the command.
43
+ email: postmodern.mod3@gmail.com
44
+ executables:
45
+ - command_mapper-gen
46
+ extensions: []
47
+ extra_rdoc_files:
48
+ - ChangeLog.md
49
+ - LICENSE.txt
50
+ - README.md
51
+ files:
52
+ - ".github/workflows/ruby.yml"
53
+ - ".gitignore"
54
+ - ".rspec"
55
+ - ".yardopts"
56
+ - ChangeLog.md
57
+ - Gemfile
58
+ - LICENSE.txt
59
+ - README.md
60
+ - Rakefile
61
+ - bin/command_mapper-gen
62
+ - commnad_mapper-gen.gemspec
63
+ - examples/grep.rb
64
+ - gemspec.yml
65
+ - lib/command_mapper/gen.rb
66
+ - lib/command_mapper/gen/arg.rb
67
+ - lib/command_mapper/gen/argument.rb
68
+ - lib/command_mapper/gen/cli.rb
69
+ - lib/command_mapper/gen/command.rb
70
+ - lib/command_mapper/gen/exceptions.rb
71
+ - lib/command_mapper/gen/option.rb
72
+ - lib/command_mapper/gen/option_value.rb
73
+ - lib/command_mapper/gen/parsers.rb
74
+ - lib/command_mapper/gen/parsers/common.rb
75
+ - lib/command_mapper/gen/parsers/help.rb
76
+ - lib/command_mapper/gen/parsers/man.rb
77
+ - lib/command_mapper/gen/parsers/options.rb
78
+ - lib/command_mapper/gen/parsers/usage.rb
79
+ - lib/command_mapper/gen/task.rb
80
+ - lib/command_mapper/gen/types.rb
81
+ - lib/command_mapper/gen/types/enum.rb
82
+ - lib/command_mapper/gen/types/key_value.rb
83
+ - lib/command_mapper/gen/types/list.rb
84
+ - lib/command_mapper/gen/types/map.rb
85
+ - lib/command_mapper/gen/types/num.rb
86
+ - lib/command_mapper/gen/types/str.rb
87
+ - lib/command_mapper/gen/version.rb
88
+ - spec/argument_spec.rb
89
+ - spec/cli_spec.rb
90
+ - spec/command_spec.rb
91
+ - spec/option_spec.rb
92
+ - spec/option_value_spec.rb
93
+ - spec/parsers/common_spec.rb
94
+ - spec/parsers/help_spec.rb
95
+ - spec/parsers/man_spec.rb
96
+ - spec/parsers/options_spec.rb
97
+ - spec/parsers/usage_spec.rb
98
+ - spec/spec_helper.rb
99
+ - spec/task_spec.rb
100
+ - spec/types/enum_spec.rb
101
+ - spec/types/key_value_spec.rb
102
+ - spec/types/list_spec.rb
103
+ - spec/types/map_spec.rb
104
+ - spec/types/str_spec.rb
105
+ homepage: https://github.com/postmodern/command_mapper-gen.rb#readme
106
+ licenses:
107
+ - MIT
108
+ metadata:
109
+ documentation_uri: https://rubydoc.info/gems/command_mapper-gen
110
+ source_code_uri: https://github.com/postmodern/command_mapper-gen.rb
111
+ bug_tracker_uri: https://github.com/postmodern/command_mapper-gen.rb/issues
112
+ changelog_uri: https://github.com/postmodern/command_mapper-gen.rb/blob/master/ChangeLog.md
113
+ rubygems_mfa_required: 'true'
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: 2.0.0
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubygems_version: 3.2.22
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Generates command_mapper Ruby classes for a given command
133
+ test_files: []