gli 2.18.1 → 2.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +28 -0
  3. data/.gitignore +1 -3
  4. data/.tool-versions +1 -1
  5. data/Gemfile +0 -6
  6. data/README.rdoc +28 -18
  7. data/Rakefile +15 -37
  8. data/bin/ci +29 -0
  9. data/bin/gli +25 -64
  10. data/bin/rake +29 -0
  11. data/bin/setup +5 -0
  12. data/exe/gli +68 -0
  13. data/gli.gemspec +19 -22
  14. data/gli.rdoc +2 -2
  15. data/lib/gli/command_support.rb +2 -6
  16. data/lib/gli/commands/help_modules/arg_name_formatter.rb +2 -2
  17. data/lib/gli/commands/help_modules/command_help_format.rb +1 -1
  18. data/lib/gli/commands/help_modules/global_help_format.rb +1 -1
  19. data/lib/gli/commands/scaffold.rb +18 -93
  20. data/lib/gli/dsl.rb +1 -1
  21. data/lib/gli/options.rb +2 -2
  22. data/lib/gli/version.rb +1 -1
  23. data/object-model.dot +29 -0
  24. data/object-model.png +0 -0
  25. data/test/apps/todo/Gemfile +1 -1
  26. data/test/apps/todo/bin/todo +1 -1
  27. data/test/integration/gli_cli_test.rb +69 -0
  28. data/test/integration/gli_powered_app_test.rb +52 -0
  29. data/test/integration/scaffold_test.rb +30 -0
  30. data/test/integration/test_helper.rb +52 -0
  31. data/test/{tc_command_finder.rb → unit/command_finder_test.rb} +6 -6
  32. data/test/{tc_command.rb → unit/command_test.rb} +4 -4
  33. data/test/unit/compound_command_test.rb +17 -0
  34. data/test/{tc_doc.rb → unit/doc_test.rb} +38 -51
  35. data/test/{tc_flag.rb → unit/flag_test.rb} +19 -25
  36. data/test/{tc_gli.rb → unit/gli_test.rb} +28 -47
  37. data/test/{tc_help.rb → unit/help_test.rb} +48 -107
  38. data/test/{init_simplecov.rb → unit/init_simplecov.rb} +0 -0
  39. data/test/{tc_options.rb → unit/options_test.rb} +4 -4
  40. data/test/unit/subcommand_parsing_test.rb +263 -0
  41. data/test/unit/subcommands_test.rb +245 -0
  42. data/test/{fake_std_out.rb → unit/support/fake_std_out.rb} +0 -0
  43. data/test/{config.yaml → unit/support/gli_test_config.yml} +0 -0
  44. data/test/unit/switch_test.rb +49 -0
  45. data/test/{tc_terminal.rb → unit/terminal_test.rb} +4 -3
  46. data/test/unit/test_helper.rb +13 -0
  47. data/test/unit/verbatim_wrapper_test.rb +24 -0
  48. metadata +61 -126
  49. data/.ruby-gemset +0 -1
  50. data/.ruby-version +0 -1
  51. data/.travis.yml +0 -11
  52. data/ObjectModel.graffle +0 -1191
  53. data/bin/report_on_rake_results +0 -10
  54. data/bin/test_all_rubies.sh +0 -6
  55. data/features/gli_executable.feature +0 -90
  56. data/features/gli_init.feature +0 -234
  57. data/features/step_definitions/gli_executable_steps.rb +0 -18
  58. data/features/step_definitions/gli_init_steps.rb +0 -11
  59. data/features/step_definitions/todo_steps.rb +0 -100
  60. data/features/support/env.rb +0 -54
  61. data/features/todo.feature +0 -579
  62. data/features/todo_legacy.feature +0 -130
  63. data/test/option_test_helper.rb +0 -13
  64. data/test/tc_compound_command.rb +0 -22
  65. data/test/tc_subcommand_parsing.rb +0 -280
  66. data/test/tc_subcommands.rb +0 -259
  67. data/test/tc_switch.rb +0 -55
  68. data/test/tc_verbatim_wrapper.rb +0 -36
  69. data/test/test_helper.rb +0 -21
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'yaml'
3
- require 'rainbow'
4
-
5
- results = YAML::load(STDIN)
6
- success = results["successes"] || []
7
- errors = results["errors"] || []
8
- success.each { |ruby| puts ruby.color(:green) }
9
- errors.each { |ruby| puts ruby.color(:red) }
10
- exit -1 unless errors.empty?
@@ -1,6 +0,0 @@
1
- echo tests
2
- rvm 1.9.2@gli-dev,1.9.3@gli-dev,1.8.7@gli-dev,jruby@gli-dev,rbx@gli-dev,ree@gli-dev --yaml rake test | bin/report_on_rake_results
3
- rake clobber > /dev/null 2>&1
4
- echo features
5
- rvm 1.9.2@gli-dev,1.9.3@gli-dev,1.8.7@gli-dev,jruby@gli-dev,rbx@gli-dev,ree@gli-dev --yaml rake features | bin/report_on_rake_results
6
- rake clobber > /dev/null 2>&1
@@ -1,90 +0,0 @@
1
- Feature: The GLI executable works as intended
2
- As a developer who wants to make a GLI-powered command-line app
3
- When I use the app provided by GLI
4
- I get a reasonably working application
5
-
6
- Background:
7
- Given I have GLI installed
8
- And my terminal size is "80x24"
9
-
10
- Scenario Outline: Getting Help for GLI
11
- When I run `gli <command>`
12
- Then the exit status should be 0
13
- And the output should contain:
14
- """
15
- NAME
16
- gli - create scaffolding for a GLI-powered application
17
-
18
- SYNOPSIS
19
- gli [global options] command [command options] [arguments...]
20
-
21
- VERSION
22
- """
23
- And the output should contain:
24
- """
25
- GLOBAL OPTIONS
26
- --help - Show this message
27
- -n - Dry run; dont change the disk
28
- -r, --root=arg - Root dir of project (default: .)
29
- -v - Be verbose
30
- --version - Display the program version
31
-
32
- COMMANDS
33
- help - Shows a list of commands or help for one command
34
- init, scaffold - Create a new GLI-based project
35
- """
36
-
37
- Examples:
38
- |command|
39
- | |
40
- |help |
41
-
42
-
43
- Scenario Outline: Getting help on scaffolding
44
- When I run `gli help <command>`
45
- Then the exit status should be 0
46
- And the output should contain:
47
- """
48
- NAME
49
- init - Create a new GLI-based project
50
-
51
- SYNOPSIS
52
- gli [global options] init [command options] project_name [command_name][, [command_name]]*
53
-
54
- DESCRIPTION
55
- This will create a scaffold command line project that uses GLI for command
56
- line processing. Specifically, this will create an executable ready to go,
57
- as well as a lib and test directory, all inside the directory named for your
58
- project
59
-
60
- COMMAND OPTIONS
61
- -e, --[no-]ext - Create an ext dir
62
- --[no-]force - Overwrite/ignore existing files and directories
63
- --notest - Do not create a test or features dir
64
- """
65
-
66
- Examples:
67
- |command |
68
- |init |
69
- |scaffold |
70
-
71
-
72
- Scenario: GLI correctly identifies non-existent command
73
- When I run `gli foobar`
74
- Then the exit status should not be 0
75
- And the stderr should contain "error: Unknown command 'foobar'"
76
-
77
- Scenario: GLI correctly identifies non-existent global flag
78
- When I run `gli -q help`
79
- Then the exit status should not be 0
80
- And the stderr should contain "error: Unknown option -q"
81
-
82
- Scenario: GLI correctly identifies non-existent command flag
83
- When I run `gli init -q`
84
- Then the exit status should not be 0
85
- And the stderr should contain "error: Unknown option -q"
86
-
87
- Scenario: The _doc command doesn't blow up
88
- Given the file "gli.rdoc" doesn't exist
89
- When I run `gli _doc`
90
- Then a file named "gli.rdoc" should exist
@@ -1,234 +0,0 @@
1
- Feature: The scaffold GLI generates works
2
- As a developer who wants to make a GLI-powered command-line app
3
- When I generate a GLI-powered app
4
- Things work out of the box
5
-
6
- Background:
7
- Given I have GLI installed
8
- And GLI's libs are in my path
9
- And my terminal size is "80x24"
10
-
11
- Scenario: Scaffold generates and things look good
12
- When I run `gli init --rvmrc todo add complete list`
13
- Then the exit status should be 0
14
- And the output should contain exactly:
15
- """
16
- Creating dir ./todo/lib...
17
- Creating dir ./todo/bin...
18
- Creating dir ./todo/test...
19
- Created ./todo/bin/todo
20
- Created ./todo/README.rdoc
21
- Created ./todo/todo.rdoc
22
- Created ./todo/todo.gemspec
23
- Created ./todo/test/default_test.rb
24
- Created ./todo/test/test_helper.rb
25
- Created ./todo/Rakefile
26
- Created ./todo/Gemfile
27
- Created ./todo/features
28
- Created ./todo/lib/todo/version.rb
29
- Created ./todo/lib/todo.rb
30
- Created ./todo/.rvmrc
31
-
32
- """
33
- And the following directories should exist:
34
- |todo |
35
- |todo/bin |
36
- |todo/test |
37
- |todo/lib |
38
- And the following files should exist:
39
- |todo/bin/todo |
40
- |todo/README.rdoc |
41
- |todo/todo.rdoc |
42
- |todo/todo.gemspec |
43
- |todo/test/default_test.rb |
44
- |todo/test/test_helper.rb |
45
- |todo/Rakefile |
46
- |todo/Gemfile |
47
- |todo/lib/todo/version.rb |
48
- |todo/lib/todo.rb |
49
- |todo/.rvmrc |
50
- And the file "todo/README.rdoc" should contain ":include:todo.rdoc"
51
- And the file "todo/todo.rdoc" should contain "todo _doc"
52
- When I cd to "todo"
53
- And I make sure todo's lib dir is in my lib path
54
- And I run `bin/todo`
55
- Then the output should contain:
56
- """
57
- NAME
58
- todo - Describe your application here
59
-
60
- SYNOPSIS
61
- todo [global options] command [command options] [arguments...]
62
-
63
- VERSION
64
- 0.0.1
65
-
66
- GLOBAL OPTIONS
67
- -f, --flagname=The name of the argument - Describe some flag here (default:
68
- the default)
69
- --help - Show this message
70
- -s, --[no-]switch - Describe some switch here
71
- --version - Display the program version
72
-
73
- COMMANDS
74
- add - Describe add here
75
- complete - Describe complete here
76
- help - Shows a list of commands or help for one command
77
- list - Describe list here
78
-
79
- """
80
- And I run `bin/todo --help`
81
- Then the output should contain:
82
- """
83
- NAME
84
- todo - Describe your application here
85
-
86
- SYNOPSIS
87
- todo [global options] command [command options] [arguments...]
88
-
89
- VERSION
90
- 0.0.1
91
-
92
- GLOBAL OPTIONS
93
- -f, --flagname=The name of the argument - Describe some flag here (default:
94
- the default)
95
- --help - Show this message
96
- -s, --[no-]switch - Describe some switch here
97
- --version - Display the program version
98
-
99
- COMMANDS
100
- add - Describe add here
101
- complete - Describe complete here
102
- help - Shows a list of commands or help for one command
103
- list - Describe list here
104
-
105
- """
106
- When I run `bin/todo help add`
107
- Then the output should contain:
108
- """
109
- NAME
110
- add - Describe add here
111
- """
112
- And the output should contain:
113
- """
114
- SYNOPSIS
115
- todo [global options] add [command options] Describe arguments to add here
116
- """
117
- And the output should contain:
118
- """
119
- COMMAND OPTIONS
120
- -f arg - Describe a flag to add (default: default)
121
- -s - Describe a switch to add
122
- """
123
- When I run `rake test`
124
- Then the output should contain:
125
- """
126
- .
127
- """
128
- And the output should contain:
129
- """
130
-
131
- 1 tests, 1 assertions, 0 failures, 0 errors
132
- """
133
- Given todo's libs are no longer in my load path
134
- When I run `rake features`
135
- Then the output should contain:
136
- """
137
- 1 scenario (1 passed)
138
- """
139
- And the output should contain:
140
- """
141
- 2 steps (2 passed)
142
- """
143
-
144
- Scenario Outline: Scaffold generates and respects flags to create ext dir and avoid test dir
145
- When I run `<command>`
146
- Then the exit status should be 0
147
- And the output should contain exactly:
148
- """
149
- Creating dir ./todo/lib...
150
- Creating dir ./todo/bin...
151
- Creating dir ./todo/ext...
152
- Created ./todo/bin/todo
153
- Created ./todo/README.rdoc
154
- Created ./todo/todo.rdoc
155
- Created ./todo/todo.gemspec
156
- Created ./todo/Rakefile
157
- Created ./todo/Gemfile
158
- Created ./todo/lib/todo/version.rb
159
- Created ./todo/lib/todo.rb
160
-
161
- """
162
- And the following directories should exist:
163
- |todo |
164
- |todo/bin |
165
- |todo/ext |
166
- |todo/lib |
167
- And the following directories should not exist:
168
- |todo/test|
169
- And the following files should exist:
170
- |todo/bin/todo |
171
- |todo/README.rdoc |
172
- |todo/todo.rdoc |
173
- |todo/todo.gemspec |
174
- |todo/Rakefile |
175
- |todo/Gemfile |
176
- |todo/lib/todo/version.rb |
177
- |todo/lib/todo.rb |
178
-
179
- Examples:
180
- | command |
181
- | gli init -e --notest todo add complete list |
182
- | gli init todo add complete list -e --notest |
183
-
184
- Scenario: Running commands the normal way
185
- Given I successfully run `gli init todo add complete compute list`
186
- And I cd to "todo"
187
- And I make sure todo's lib dir is in my lib path
188
- When I successfully run `bin/todo add`
189
- Then the output should contain "add command ran"
190
- When I successfully run `bin/todo complete`
191
- Then the output should contain "complete command ran"
192
- When I run `bin/todo foobar`
193
- Then the stderr should contain "error: Unknown command 'foobar'"
194
- And the exit status should not be 0
195
-
196
- Scenario: Running commands using short form
197
- Given I successfully run `gli init todo add complete compute list`
198
- And I cd to "todo"
199
- And I make sure todo's lib dir is in my lib path
200
- When I successfully run `bin/todo a`
201
- Then the output should contain "add command ran"
202
- When I successfully run `bin/todo l`
203
- Then the output should contain "list command ran"
204
- When I successfully run `bin/todo compl`
205
- Then the output should contain "complete command ran"
206
-
207
- Scenario: Ambiguous commands give helpful output
208
- Given I successfully run `gli init todo add complete compute list`
209
- And I cd to "todo"
210
- And I make sure todo's lib dir is in my lib path
211
- When I run `bin/todo comp`
212
- Then the stderr should contain "Ambiguous command 'comp'. It matches complete,compute"
213
- And the exit status should not be 0
214
-
215
- Scenario: Running generated command without bundler gives a helpful error message
216
- Given I successfully run `gli init todo add complete compute list`
217
- And I cd to "todo"
218
- When I run `bin/todo comp`
219
- Then the exit status should not be 0
220
- Then the stderr should contain "In development, you need to use `bundle exec bin/todo` to run your app"
221
- And the stderr should contain "At install-time, RubyGems will make sure lib, etc. are in the load path"
222
- And the stderr should contain "Feel free to remove this message from bin/todo now"
223
-
224
- Scenario: Running commands with a dash in the name
225
- Given I successfully run `gli init todo-app add complete compute list`
226
- And I cd to "todo-app"
227
- And I make sure todo's lib dir is in my lib path
228
- When I successfully run `bin/todo-app add`
229
- Then the output should contain "add command ran"
230
- When I successfully run `bin/todo-app complete`
231
- Then the output should contain "complete command ran"
232
- When I run `bin/todo-app foobar`
233
- Then the stderr should contain "error: Unknown command 'foobar'"
234
- And the exit status should not be 0
@@ -1,18 +0,0 @@
1
- Given /^I have GLI installed$/ do
2
- add_to_lib_path(GLI_LIB_PATH)
3
- end
4
-
5
- Given /^my terminal size is "([^"]*)"$/ do |terminal_size|
6
- if terminal_size =~/^(\d+)x(\d+)$/
7
- ENV['COLUMNS'] = $1
8
- ENV['LINES'] = $2
9
- else
10
- raise "Terminal size should be COLxLines, e.g. 80x24"
11
- end
12
- end
13
-
14
-
15
- Given /^the file "(.*?)" doesn't exist$/ do |filename|
16
- FileUtils.rm filename if File.exist?(filename)
17
- end
18
-
@@ -1,11 +0,0 @@
1
- Given /^GLI's libs are in my path$/ do
2
- ENV['RUBYLIB'] = GLI_LIB_PATH
3
- end
4
-
5
- Given /^I make sure todo's lib dir is in my lib path$/ do
6
- add_to_lib_path("./lib")
7
- end
8
-
9
- Given /^todo's libs are no longer in my load path$/ do
10
- remove_from_lib_path("./lib")
11
- end
@@ -1,100 +0,0 @@
1
- Given /^todo_legacy's bin directory is in my path/ do
2
- add_to_path(File.expand_path(File.join(File.dirname(__FILE__),'..','..','test','apps','todo_legacy','bin')))
3
- end
4
-
5
- Given /^todo's bin directory is in my path/ do
6
- add_to_path(File.expand_path(File.join(File.dirname(__FILE__),'..','..','test','apps','todo','bin')))
7
- end
8
-
9
- Given /^the todo app is coded to avoid sorted help commands$/ do
10
- ENV['TODO_SORT_HELP'] = 'manually'
11
- end
12
-
13
- Given /^the todo app is coded to avoid wrapping text$/ do
14
- ENV['TODO_WRAP_HELP_TEXT'] = 'one_line'
15
- end
16
-
17
- Given /^the todo app is coded to wrap text only for tty$/ do
18
- ENV['TODO_WRAP_HELP_TEXT'] = 'tty_only'
19
- end
20
-
21
- Given /^the todo app is coded to hide commands without description$/ do
22
- ENV['HIDE_COMMANDS_WITHOUT_DESC'] = 'true'
23
- end
24
-
25
- Given /^a clean home directory$/ do
26
- FileUtils.rm_rf File.join(ENV['HOME'],'gli_test_todo.rc')
27
- end
28
-
29
- Then /^the config file should contain a section for each command and subcommand$/ do
30
- config = File.open(File.join(ENV['HOME'],'gli_test_todo.rc')) do |file|
31
- YAML::load(file)
32
- end
33
- expect(config.keys).to include(:flag)
34
- expect(config[:flag]).to eq('foo')
35
- config[:flag].tap do |flag|
36
- if flag.respond_to?(:encoding)
37
- expect(flag.encoding.name).to eq('UTF-8')
38
- end
39
- end
40
- expect(config.keys).to include(:switch)
41
- expect(config[:switch]).to eq(true)
42
- expect(config.keys).to include(:otherswitch)
43
- expect(config[:otherswitch]).to eq(false)
44
- expect(config.keys).to include('commands')
45
- %w(chained chained2 create first list ls second).map(&:to_sym).each do |command_name|
46
- expect(config['commands'].keys).to include(command_name)
47
- end
48
- expect(config['commands'][:create].keys).to include('commands')
49
- expect(config['commands'][:create]['commands']).to include(:tasks)
50
- expect(config['commands'][:create]['commands']).to include(:contexts)
51
-
52
- expect(config['commands'][:list].keys).to include('commands')
53
- expect(config['commands'][:list]['commands']).to include(:tasks)
54
- expect(config['commands'][:list]['commands']).to include(:contexts)
55
- end
56
-
57
- Given /^a config file that specifies defaults for some commands with subcommands$/ do
58
- @config = {
59
- 'commands' => {
60
- :list => {
61
- 'commands' => {
62
- :tasks => {
63
- :flag => 'foobar',
64
- },
65
- :contexts => {
66
- :otherflag => 'crud',
67
- },
68
- }
69
- }
70
- }
71
- }
72
- File.open(File.join(ENV['HOME'],'gli_test_todo.rc'),'w') do |file|
73
- file.puts @config.to_yaml
74
- end
75
- end
76
-
77
- Then /^I should see the defaults for '(.*)' from the config file in the help$/ do |command_path|
78
- if command_path == 'list tasks'
79
- step %{the output should match /--flag.*default: foobar/}
80
- expect(unescape(all_output)).not_to match(/#{unescape("--otherflag.*default: crud")}/m)
81
- elsif command_path == 'list contexts'
82
- step %{the output should match /--otherflag.*default: crud/}
83
- expect(unescape(all_output)).not_to match(/#{unescape("--flag.*default: foobar")}/m)
84
- else
85
- raise "Don't know how to test for command path #{command_path}"
86
- end
87
- end
88
-
89
-
90
- Given /^the todo app is coded to use verbatim formatting$/ do
91
- ENV['TODO_WRAP_HELP_TEXT'] = 'verbatim'
92
- end
93
-
94
- Given(/^my terminal is (\d+) characters wide$/) do |terminal_width|
95
- ENV['COLUMNS'] = terminal_width.to_s
96
- end
97
-
98
- Given(/^my app is configured for "(.*?)" synopses$/) do |synopsis|
99
- ENV['SYNOPSES'] = synopsis
100
- end