command_mapper-gen 0.1.0.pre1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/workflows/ruby.yml +27 -0
- data/.gitignore +10 -0
- data/.rspec +1 -0
- data/.yardopts +1 -0
- data/ChangeLog.md +20 -0
- data/Gemfile +17 -0
- data/LICENSE.txt +20 -0
- data/README.md +145 -0
- data/Rakefile +15 -0
- data/bin/command_mapper-gen +7 -0
- data/commnad_mapper-gen.gemspec +61 -0
- data/examples/grep.rb +63 -0
- data/gemspec.yml +26 -0
- data/lib/command_mapper/gen/arg.rb +43 -0
- data/lib/command_mapper/gen/argument.rb +53 -0
- data/lib/command_mapper/gen/cli.rb +233 -0
- data/lib/command_mapper/gen/command.rb +202 -0
- data/lib/command_mapper/gen/exceptions.rb +9 -0
- data/lib/command_mapper/gen/option.rb +66 -0
- data/lib/command_mapper/gen/option_value.rb +23 -0
- data/lib/command_mapper/gen/parsers/common.rb +49 -0
- data/lib/command_mapper/gen/parsers/help.rb +351 -0
- data/lib/command_mapper/gen/parsers/man.rb +80 -0
- data/lib/command_mapper/gen/parsers/options.rb +127 -0
- data/lib/command_mapper/gen/parsers/usage.rb +141 -0
- data/lib/command_mapper/gen/parsers.rb +2 -0
- data/lib/command_mapper/gen/task.rb +90 -0
- data/lib/command_mapper/gen/types/enum.rb +30 -0
- data/lib/command_mapper/gen/types/key_value.rb +34 -0
- data/lib/command_mapper/gen/types/list.rb +34 -0
- data/lib/command_mapper/gen/types/map.rb +36 -0
- data/lib/command_mapper/gen/types/num.rb +18 -0
- data/lib/command_mapper/gen/types/str.rb +48 -0
- data/lib/command_mapper/gen/types.rb +6 -0
- data/lib/command_mapper/gen/version.rb +6 -0
- data/lib/command_mapper/gen.rb +2 -0
- data/spec/argument_spec.rb +92 -0
- data/spec/cli_spec.rb +269 -0
- data/spec/command_spec.rb +316 -0
- data/spec/option_spec.rb +85 -0
- data/spec/option_value_spec.rb +20 -0
- data/spec/parsers/common_spec.rb +616 -0
- data/spec/parsers/help_spec.rb +612 -0
- data/spec/parsers/man_spec.rb +158 -0
- data/spec/parsers/options_spec.rb +802 -0
- data/spec/parsers/usage_spec.rb +1175 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/task_spec.rb +69 -0
- data/spec/types/enum_spec.rb +45 -0
- data/spec/types/key_value_spec.rb +36 -0
- data/spec/types/list_spec.rb +36 -0
- data/spec/types/map_spec.rb +48 -0
- data/spec/types/str_spec.rb +70 -0
- metadata +133 -0
@@ -0,0 +1,158 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'command_mapper/gen/parsers/man'
|
3
|
+
|
4
|
+
describe CommandMapper::Gen::Parsers::Man do
|
5
|
+
let(:command_name) { 'yes' }
|
6
|
+
let(:command) { CommandMapper::Gen::Command.new(command_name) }
|
7
|
+
|
8
|
+
subject { described_class.new(command) }
|
9
|
+
|
10
|
+
let(:output) do
|
11
|
+
<<MAN_PAGE
|
12
|
+
YES(1) User Commands YES(1)
|
13
|
+
|
14
|
+
NAME
|
15
|
+
yes - output a string repeatedly until killed
|
16
|
+
|
17
|
+
SYNOPSIS
|
18
|
+
yes [STRING]...
|
19
|
+
yes OPTION
|
20
|
+
|
21
|
+
DESCRIPTION
|
22
|
+
Repeatedly output a line with all specified STRING(s), or 'y'.
|
23
|
+
|
24
|
+
--help display this help and exit
|
25
|
+
|
26
|
+
--version
|
27
|
+
output version information and exit
|
28
|
+
|
29
|
+
AUTHOR
|
30
|
+
Written by David MacKenzie.
|
31
|
+
|
32
|
+
REPORTING BUGS
|
33
|
+
GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
|
34
|
+
Report any translation bugs to <https://translationproject.org/team/>
|
35
|
+
|
36
|
+
COPYRIGHT
|
37
|
+
Copyright © 2020 Free Software Foundation, Inc. License GPLv3+: GNU GPL version
|
38
|
+
3 or later <https://gnu.org/licenses/gpl.html>.
|
39
|
+
This is free software: you are free to change and redistribute it. There is NO
|
40
|
+
WARRANTY, to the extent permitted by law.
|
41
|
+
|
42
|
+
SEE ALSO
|
43
|
+
Full documentation <https://www.gnu.org/software/coreutils/yes>
|
44
|
+
or available locally via: info '(coreutils) yes invocation'
|
45
|
+
|
46
|
+
GNU coreutils 8.32 July 2021 YES(1)
|
47
|
+
MAN_PAGE
|
48
|
+
end
|
49
|
+
|
50
|
+
describe ".run" do
|
51
|
+
subject { described_class }
|
52
|
+
|
53
|
+
context "when the command has a man page" do
|
54
|
+
before do
|
55
|
+
allow(subject).to receive(:`).with("man #{command_name} 2>/dev/null").and_return(output)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "must parse the command's man page, populate the command, and return the command" do
|
59
|
+
parsed_command = subject.run(command)
|
60
|
+
|
61
|
+
expect(parsed_command).to be(command)
|
62
|
+
|
63
|
+
expect(parsed_command.arguments.keys).to eq([:string])
|
64
|
+
expect(parsed_command.arguments[:string]).to be_kind_of(CommandMapper::Gen::Argument)
|
65
|
+
|
66
|
+
expect(parsed_command.options.keys).to eq(%w[--help --version])
|
67
|
+
expect(parsed_command.options['--help']).to be_kind_of(CommandMapper::Gen::Option)
|
68
|
+
expect(parsed_command.options['--version']).to be_kind_of(CommandMapper::Gen::Option)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "when the command has no man page" do
|
73
|
+
let(:command_name) { 'foo' }
|
74
|
+
|
75
|
+
it "must return nil" do
|
76
|
+
expect(subject.run(command)).to be(nil)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "but the `man` command is not installed" do
|
81
|
+
before do
|
82
|
+
allow(subject).to receive(:`).with("man #{command_name} 2>/dev/null").and_raise(Errno::ENOENT.new("man"))
|
83
|
+
end
|
84
|
+
|
85
|
+
it do
|
86
|
+
expect {
|
87
|
+
subject.run(command)
|
88
|
+
}.to raise_error(CommandMapper::Gen::CommandNotInstalled,"the 'man' command is not installed")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "#parse" do
|
94
|
+
before { subject.parse(output) }
|
95
|
+
|
96
|
+
context "when the arguments are defined in the DESCRIPTION section" do
|
97
|
+
it "must populate the command's options" do
|
98
|
+
expect(command.options.keys).to eq(%w[--help --version])
|
99
|
+
expect(command.options['--help']).to be_kind_of(CommandMapper::Gen::Option)
|
100
|
+
expect(command.options['--version']).to be_kind_of(CommandMapper::Gen::Option)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context "when the arguments are defined in the OPTIONS section" do
|
105
|
+
let(:output) do
|
106
|
+
<<MAN_PAGE
|
107
|
+
YES(1) User Commands YES(1)
|
108
|
+
|
109
|
+
NAME
|
110
|
+
yes - output a string repeatedly until killed
|
111
|
+
|
112
|
+
SYNOPSIS
|
113
|
+
yes [STRING]...
|
114
|
+
yes OPTION
|
115
|
+
|
116
|
+
DESCRIPTION
|
117
|
+
Repeatedly output a line with all specified STRING(s), or 'y'.
|
118
|
+
|
119
|
+
OPTIONS
|
120
|
+
--help display this help and exit
|
121
|
+
|
122
|
+
--version
|
123
|
+
output version information and exit
|
124
|
+
|
125
|
+
AUTHOR
|
126
|
+
Written by David MacKenzie.
|
127
|
+
|
128
|
+
REPORTING BUGS
|
129
|
+
GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
|
130
|
+
Report any translation bugs to <https://translationproject.org/team/>
|
131
|
+
|
132
|
+
COPYRIGHT
|
133
|
+
Copyright © 2020 Free Software Foundation, Inc. License GPLv3+: GNU GPL version
|
134
|
+
3 or later <https://gnu.org/licenses/gpl.html>.
|
135
|
+
This is free software: you are free to change and redistribute it. There is NO
|
136
|
+
WARRANTY, to the extent permitted by law.
|
137
|
+
|
138
|
+
SEE ALSO
|
139
|
+
Full documentation <https://www.gnu.org/software/coreutils/yes>
|
140
|
+
or available locally via: info '(coreutils) yes invocation'
|
141
|
+
|
142
|
+
GNU coreutils 8.32 July 2021 YES(1)
|
143
|
+
MAN_PAGE
|
144
|
+
end
|
145
|
+
|
146
|
+
it "must populate the command's options" do
|
147
|
+
expect(command.options.keys).to eq(%w[--help --version])
|
148
|
+
expect(command.options['--help']).to be_kind_of(CommandMapper::Gen::Option)
|
149
|
+
expect(command.options['--version']).to be_kind_of(CommandMapper::Gen::Option)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
it "must populate the command's arguments" do
|
154
|
+
expect(command.arguments.keys).to eq([:string])
|
155
|
+
expect(command.arguments[:string]).to be_kind_of(CommandMapper::Gen::Argument)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|