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,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