rubycom 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +8 -8
  2. data/README.md +162 -146
  3. data/Rakefile +12 -12
  4. data/lib/rubycom.rb +156 -226
  5. data/lib/rubycom/arg_parse.rb +252 -0
  6. data/lib/rubycom/command_interface.rb +97 -0
  7. data/lib/rubycom/completions.rb +62 -0
  8. data/lib/rubycom/error_handler.rb +15 -0
  9. data/lib/rubycom/executor.rb +23 -0
  10. data/lib/rubycom/helpers.rb +98 -0
  11. data/lib/rubycom/output_handler.rb +15 -0
  12. data/lib/rubycom/parameter_extract.rb +262 -0
  13. data/lib/rubycom/singleton_commands.rb +78 -0
  14. data/lib/rubycom/sources.rb +99 -0
  15. data/lib/rubycom/version.rb +1 -1
  16. data/lib/rubycom/yard_doc.rb +146 -0
  17. data/rubycom.gemspec +14 -16
  18. data/test/rubycom/arg_parse_test.rb +247 -0
  19. data/test/rubycom/command_interface_test.rb +293 -0
  20. data/test/rubycom/completions_test.rb +94 -0
  21. data/test/rubycom/error_handler_test.rb +72 -0
  22. data/test/rubycom/executor_test.rb +64 -0
  23. data/test/rubycom/helpers_test.rb +467 -0
  24. data/test/rubycom/output_handler_test.rb +76 -0
  25. data/test/rubycom/parameter_extract_test.rb +141 -0
  26. data/test/rubycom/rubycom_test.rb +290 -548
  27. data/test/rubycom/singleton_commands_test.rb +122 -0
  28. data/test/rubycom/sources_test.rb +59 -0
  29. data/test/rubycom/util_test_bin.rb +8 -0
  30. data/test/rubycom/util_test_composite.rb +23 -20
  31. data/test/rubycom/util_test_module.rb +142 -112
  32. data/test/rubycom/util_test_no_singleton.rb +2 -2
  33. data/test/rubycom/util_test_sub_module.rb +13 -0
  34. data/test/rubycom/yard_doc_test.rb +165 -0
  35. metadata +61 -24
  36. data/lib/rubycom/arguments.rb +0 -133
  37. data/lib/rubycom/commands.rb +0 -63
  38. data/lib/rubycom/documentation.rb +0 -212
  39. data/test/rubycom/arguments_test.rb +0 -289
  40. data/test/rubycom/commands_test.rb +0 -51
  41. data/test/rubycom/documentation_test.rb +0 -186
  42. data/test/rubycom/util_test_job.yaml +0 -21
  43. data/test/rubycom/utility_tester.rb +0 -17
@@ -1,51 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/../../lib/rubycom/commands.rb"
2
-
3
- require "#{File.dirname(__FILE__)}/util_test_module.rb"
4
- require "#{File.dirname(__FILE__)}/util_test_composite.rb"
5
- require "#{File.dirname(__FILE__)}/util_test_no_singleton.rb"
6
-
7
- require 'test/unit'
8
-
9
- class CommandsTest < Test::Unit::TestCase
10
-
11
- def test_get_top_level_commands
12
- test_command_list = [:test_command, :test_command_no_docs, :test_command_with_arg, :test_command_arg_named_arg,
13
- :test_command_with_args, :test_command_with_options, :test_command_all_options,
14
- :test_command_options_arr, :test_command_with_return, :test_command_arg_timestamp,
15
- :test_command_arg_false, :test_command_arg_arr, :test_command_arg_hash,
16
- :test_command_mixed_options]
17
- result_command_list = Rubycom::Commands.get_top_level_commands(UtilTestModule)
18
- assert_equal(test_command_list.length, result_command_list.length)
19
- test_command_list.each { |sym|
20
- assert_includes(result_command_list, sym)
21
- }
22
- end
23
-
24
- def test_get_top_level_commands_nil_base
25
- test_command_list = []
26
- result_command_list = Rubycom::Commands.get_top_level_commands(nil)
27
- assert_equal(test_command_list.length, result_command_list.length)
28
- test_command_list.each { |sym|
29
- assert_includes(result_command_list, sym)
30
- }
31
- end
32
-
33
- def test_get_commands_nil_base
34
- test_command_list = []
35
- result_command_list = Rubycom::Commands.get_commands(nil)
36
- assert_equal(test_command_list.length, result_command_list.length)
37
- test_command_list.each { |sym|
38
- assert_includes(result_command_list, sym)
39
- }
40
- end
41
-
42
- def test_get_top_level_commands_singleton_base
43
- test_command_list = []
44
- result_command_list = Rubycom::Commands.get_top_level_commands(UtilTestNoSingleton)
45
- assert_equal(test_command_list.length, result_command_list.length)
46
- test_command_list.each { |sym|
47
- assert_includes(result_command_list, sym)
48
- }
49
- end
50
-
51
- end
@@ -1,186 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/../../lib/rubycom/documentation.rb"
2
-
3
- require "#{File.dirname(__FILE__)}/util_test_module.rb"
4
- require "#{File.dirname(__FILE__)}/util_test_composite.rb"
5
- require "#{File.dirname(__FILE__)}/util_test_no_singleton.rb"
6
-
7
- require 'test/unit'
8
-
9
- class DocumentationTest < Test::Unit::TestCase
10
-
11
- def test_get_doc
12
- method = UtilTestModule.public_method(:test_command_with_return)
13
- result_hash = Rubycom::Documentation.get_doc(method)
14
- assert_equal('A test_command with a return argument'.gsub(/\n|\r|\s/, ''), result_hash[:desc].join("\n").gsub(/\n|\r|\s/, ''))
15
- assert_equal(2, result_hash[:param].size)
16
- assert_equal('[String] test_arg a test argument'.gsub(/\n|\r|\s/, ''), result_hash[:param][0].gsub(/\n|\r|\s/, ''))
17
- assert_equal('[Integer] test_option_int an optional test argument which happens to be an Integer'.gsub(/\n|\r|\s/, ''), result_hash[:param][1].gsub(/\n|\r|\s/, ''))
18
- assert_equal(2, result_hash[:return].size)
19
- assert_equal('[Array] an array including both params if test_option_int != 1'.gsub(/\n|\r|\s/, ''), result_hash[:return][0].gsub(/\n|\r|\s/, ''))
20
- assert_equal('[String] a the first param if test_option_int == 1'.gsub(/\n|\r|\s/, ''), result_hash[:return][1].gsub(/\n|\r|\s/, ''))
21
- end
22
-
23
- def test_get_command_usage
24
- base = UtilTestModule
25
- command_name = 'test_command_arg_false'
26
- result = Rubycom::Documentation.get_command_usage(base, command_name)
27
- expected = <<-END.gsub(/^ {4}/, '')
28
- Usage: test_command_arg_false [-test_flag=false]
29
- Parameters:
30
- [Boolean] test_flag a test Boolean argument
31
- Returns:
32
- [Boolean] the flag passed in
33
- END
34
- assert_equal(expected.gsub(/\n|\r|\s/, ''), result.gsub(/\n|\r|\s/, ''))
35
- end
36
-
37
- def test_get_command_usage_nil_base
38
- base = nil
39
- command_name = 'test_command'
40
- assert_raise(Rubycom::CLIError) { Rubycom::Documentation.get_command_usage(base, command_name) }
41
- end
42
-
43
- def test_get_command_usage_nil_command
44
- base = UtilTestModule
45
- command_name = nil
46
- result = Rubycom::Documentation.get_command_usage(base, command_name)
47
- assert_equal('No command specified.', result)
48
- end
49
-
50
- def test_get_command_usage_no_command
51
- base = UtilTestModule
52
- command_name = ''
53
- result = Rubycom::Documentation.get_command_usage(base, command_name)
54
- assert_equal('No command specified.', result)
55
- end
56
-
57
- def test_get_command_usage_bad_base
58
- base = ":asd"
59
- command_name = 'test_command_with_options'
60
- assert_raise(Rubycom::CLIError) { Rubycom::Documentation.get_command_usage(base, command_name) }
61
- end
62
-
63
- def test_get_command_usage_invalid_command
64
- base = UtilTestModule
65
- command_name = '123asd!@#'
66
- assert_raise(Rubycom::CLIError) { Rubycom::Documentation.get_command_usage(base, command_name) }
67
- end
68
-
69
- def test_get_command_summary
70
- base = UtilTestModule
71
- command_name = 'test_command_with_options'
72
- expected = "test_command_with_options - A test_command with an optional argument\n"
73
- result = Rubycom::Documentation.get_command_summary(base, command_name)
74
- assert_equal(expected.gsub(/\n|\r|\s/, ''), result.gsub(/\n|\r|\s/, ''))
75
- end
76
-
77
- def test_get_command_summary_no_command
78
- base = UtilTestModule
79
- command_name = ''
80
- result = Rubycom::Documentation.get_command_summary(base, command_name)
81
- assert_equal('No command specified.', result)
82
- end
83
-
84
- def test_get_command_summary_nil_base
85
- base = nil
86
- command_name = 'test_command_with_options'
87
- assert_raise(Rubycom::CLIError) { Rubycom::Documentation.get_command_summary(base, command_name) }
88
- end
89
-
90
- def test_get_command_summary_nil_command
91
- base = UtilTestModule
92
- command_name = nil
93
- result = Rubycom::Documentation.get_command_summary(base, command_name)
94
- assert_equal('No command specified.', result)
95
- end
96
-
97
- def test_get_command_summary_wrong_base
98
- base = UtilTestNoSingleton
99
- command_name = 'test_command_with_options'
100
- assert_raise(Rubycom::CLIError) { Rubycom::Documentation.get_command_summary(base, command_name) }
101
- end
102
-
103
- def test_get_command_summary_bad_command
104
- base = UtilTestModule
105
- command_name = '!_fail_command_'
106
- assert_raise(Rubycom::CLIError) { Rubycom::Documentation.get_command_summary(base, command_name) }
107
- end
108
-
109
- def test_get_usage
110
- base = UtilTestModule
111
- result = Rubycom::Documentation.get_usage(base)
112
- expected = <<-END.gsub(/^ {4}/, '')
113
- Usage:
114
- UtilTestModule <command> [args]
115
-
116
- Commands:
117
- test_command - A basic test command
118
- test_command_no_docs
119
- test_command_with_arg - A test_command with one arg
120
- test_command_arg_named_arg - A test_command with an arg named arg
121
- test_command_with_args - A test_command with two args
122
- test_command_with_options - A test_command with an optional argument
123
- test_command_all_options - A test_command with all optional arguments
124
- test_command_options_arr - A test_command with an options array
125
- test_command_with_return - A test_command with a return argument
126
- test_command_arg_timestamp - A test_command with a Timestamp argument and an unnecessarily
127
- long description which should overflow when
128
- it tries to line up with other descriptions.
129
- test_command_arg_false - A test_command with a Boolean argument
130
- test_command_arg_arr - A test_command with an array argument
131
- test_command_arg_hash - A test_command with an Hash argument
132
- test_command_mixed_options - A test_command with several mixed options
133
-
134
- END
135
- assert_equal(expected.gsub(/\n|\r|\s/, ''), result.gsub(/\n|\r|\s/, ''))
136
- end
137
-
138
- def test_get_usage_nil_base
139
- base = nil
140
- result = Rubycom::Documentation.get_usage(base)
141
- assert_equal('', result)
142
- end
143
-
144
- def test_get_usage_no_singleton_base
145
- base = UtilTestNoSingleton
146
- result = Rubycom::Documentation.get_usage(base)
147
- assert_equal('', result)
148
- end
149
-
150
- def test_get_summary
151
- base = UtilTestModule
152
- result = Rubycom::Documentation.get_summary(base)
153
- expected = <<-END.gsub(/^ {4}/, '')
154
- Commands:
155
- test_command - A basic test command
156
- test_command_no_docs
157
- test_command_with_arg - A test_command with one arg
158
- test_command_arg_named_arg - A test_command with an arg named arg
159
- test_command_with_args - A test_command with two args
160
- test_command_with_options - A test_command with an optional argument
161
- test_command_all_options - A test_command with all optional arguments
162
- test_command_options_arr - A test_command with an options array
163
- test_command_with_return - A test_command with a return argument
164
- test_command_arg_timestamp - A test_command with a Timestamp argument and an unnecessarily
165
- long description which should overflow when
166
- it tries to line up with other descriptions.
167
- test_command_arg_false - A test_command with a Boolean argument
168
- test_command_arg_arr - A test_command with an array argument
169
- test_command_arg_hash - A test_command with an Hash argument
170
- test_command_mixed_options - A test_command with several mixed options
171
- END
172
- assert_equal(expected.gsub(/\n|\r|\s/, ''), result.gsub(/\n|\r|\s/, ''))
173
- end
174
-
175
- def test_get_summary_nil_base
176
- base = nil
177
- result = Rubycom::Documentation.get_summary(base)
178
- assert_equal('No Commands found for .', result)
179
- end
180
-
181
- def test_get_summary_no_singleton_base
182
- base = UtilTestNoSingleton
183
- result = Rubycom::Documentation.get_summary(base)
184
- assert_equal('No Commands found for UtilTestNoSingleton.', result)
185
- end
186
- end
@@ -1,21 +0,0 @@
1
- ---
2
- env:
3
- test_msg: Hello World
4
- test_arg: 123
5
- working_dir: ./test/rubycom
6
- steps:
7
- 1:
8
- desc: Run test_composite_command with environment variable
9
- cmd: ruby env[working_dir]/util_test_composite.rb test_composite_command env[test_msg]
10
- 2:
11
- Var: Run UtilTestModule/test_command_options_arr with environment variable
12
- cmd: ruby env[working_dir]/util_test_composite.rb UtilTestModule test_command_options_arr '["Hello World 1", world2]'
13
- 3:
14
- Cntxt: Run test_command_with_args with environment variable
15
- cmd: ruby env[working_dir]/util_test_module.rb test_command_with_args env[test_msg] env[test_arg]
16
- 4:
17
- Cmd: Run ls for arbitrary command support
18
- cmd: ls
19
- 5:
20
- Arbitrary_Context: Run ls with environment variable
21
- cmd: ls env[working_dir]
@@ -1,17 +0,0 @@
1
- require 'time'
2
-
3
- require "#{File.expand_path(File.dirname(__FILE__))}/../../lib/rubycom.rb"
4
- require "#{File.expand_path(File.dirname(__FILE__))}/util_test_module.rb"
5
- require "#{File.expand_path(File.dirname(__FILE__))}/util_test_composite.rb"
6
- require "#{File.expand_path(File.dirname(__FILE__))}/util_test_no_singleton.rb"
7
-
8
- require 'test/unit'
9
- #noinspection RubyInstanceMethodNamingConvention
10
- class TestCase < Test::Unit::TestCase
11
- def test_case
12
- base = UtilTestModule
13
- args = ["test_command_arg_hash"]
14
- result = Rubycom.run(base, args)
15
- puts result
16
- end
17
- end