gli 2.19.2 → 2.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +28 -0
  3. data/.gitignore +1 -3
  4. data/Gemfile +0 -6
  5. data/README.rdoc +2 -12
  6. data/Rakefile +15 -37
  7. data/bin/ci +29 -0
  8. data/bin/gli +25 -64
  9. data/bin/rake +29 -0
  10. data/bin/setup +5 -0
  11. data/exe/gli +68 -0
  12. data/gli.gemspec +19 -21
  13. data/gli.rdoc +2 -2
  14. data/lib/gli/commands/help_modules/command_help_format.rb +1 -1
  15. data/lib/gli/commands/help_modules/global_help_format.rb +1 -1
  16. data/lib/gli/commands/scaffold.rb +9 -93
  17. data/lib/gli/options.rb +2 -2
  18. data/lib/gli/version.rb +1 -1
  19. data/object-model.dot +29 -0
  20. data/object-model.png +0 -0
  21. data/test/apps/todo/Gemfile +1 -1
  22. data/test/apps/todo/bin/todo +1 -1
  23. data/test/integration/gli_cli_test.rb +69 -0
  24. data/test/integration/gli_powered_app_test.rb +52 -0
  25. data/test/integration/scaffold_test.rb +30 -0
  26. data/test/integration/test_helper.rb +52 -0
  27. data/test/{tc_command_finder.rb → unit/command_finder_test.rb} +6 -6
  28. data/test/{tc_command.rb → unit/command_test.rb} +4 -4
  29. data/test/unit/compound_command_test.rb +17 -0
  30. data/test/{tc_doc.rb → unit/doc_test.rb} +38 -51
  31. data/test/{tc_flag.rb → unit/flag_test.rb} +19 -25
  32. data/test/{tc_gli.rb → unit/gli_test.rb} +28 -47
  33. data/test/{tc_help.rb → unit/help_test.rb} +48 -107
  34. data/test/{init_simplecov.rb → unit/init_simplecov.rb} +0 -0
  35. data/test/{tc_options.rb → unit/options_test.rb} +4 -4
  36. data/test/unit/subcommand_parsing_test.rb +263 -0
  37. data/test/unit/subcommands_test.rb +245 -0
  38. data/test/{fake_std_out.rb → unit/support/fake_std_out.rb} +0 -0
  39. data/test/{config.yaml → unit/support/gli_test_config.yml} +0 -0
  40. data/test/unit/switch_test.rb +49 -0
  41. data/test/{tc_terminal.rb → unit/terminal_test.rb} +4 -3
  42. data/test/unit/test_helper.rb +13 -0
  43. data/test/unit/verbatim_wrapper_test.rb +24 -0
  44. metadata +57 -124
  45. data/.ruby-gemset +0 -1
  46. data/.ruby-version +0 -1
  47. data/.travis.yml +0 -11
  48. data/ObjectModel.graffle +0 -1191
  49. data/bin/report_on_rake_results +0 -10
  50. data/bin/test_all_rubies.sh +0 -6
  51. data/features/gli_executable.feature +0 -90
  52. data/features/gli_init.feature +0 -236
  53. data/features/step_definitions/gli_executable_steps.rb +0 -18
  54. data/features/step_definitions/gli_init_steps.rb +0 -11
  55. data/features/step_definitions/todo_steps.rb +0 -100
  56. data/features/support/env.rb +0 -54
  57. data/features/support/hooks.rb +0 -5
  58. data/features/todo.feature +0 -579
  59. data/features/todo_legacy.feature +0 -130
  60. data/test/option_test_helper.rb +0 -13
  61. data/test/tc_compound_command.rb +0 -22
  62. data/test/tc_subcommand_parsing.rb +0 -280
  63. data/test/tc_subcommands.rb +0 -259
  64. data/test/tc_switch.rb +0 -55
  65. data/test/tc_verbatim_wrapper.rb +0 -36
  66. data/test/test_helper.rb +0 -21
data/gli.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  == gli - create scaffolding for a GLI-powered application
2
2
 
3
- v2.17.1
3
+ v2.19.2
4
4
 
5
5
  === Global Options
6
6
  === -r|--root arg
@@ -43,7 +43,7 @@ List commands one per line, to assist with shell completion
43
43
 
44
44
 
45
45
 
46
- ==== Command: <tt>init|scaffold project_name [command_name][, [command_name]]*</tt>
46
+ ==== Command: <tt>init|scaffold project_name [command_name]...</tt>
47
47
  Create a new GLI-based project
48
48
 
49
49
  This will create a scaffold command line project that uses GLI
@@ -53,7 +53,7 @@ COMMANDS
53
53
 
54
54
 
55
55
  <%= command_examples %>
56
- <% end %>),nil,'<>')
56
+ <% end %>))
57
57
 
58
58
 
59
59
  def flags_and_switches(command,app)
@@ -51,7 +51,7 @@ GLOBAL OPTIONS
51
51
 
52
52
  <% end %>
53
53
  COMMANDS
54
- <%= commands %>),nil,'<>')
54
+ <%= commands %>))
55
55
 
56
56
  def global_flags_and_switches
57
57
  @app.flags_declaration_order + @app.switches_declaration_order
@@ -70,10 +70,10 @@ spec = Gem::Specification.new do |s|
70
70
  s.rdoc_options << '--title' << '#{project_name}' << '--main' << 'README.rdoc' << '-ri'
71
71
  s.bindir = 'bin'
72
72
  s.executables << '#{project_name}'
73
- s.add_development_dependency('rake')
74
- s.add_development_dependency('rdoc')
75
- s.add_development_dependency('aruba')
76
- s.add_runtime_dependency('gli','#{GLI::VERSION}')
73
+ s.add_development_dependency('rake','~> 0.9.2')
74
+ s.add_development_dependency('rdoc', '~> 4.3')
75
+ s.add_development_dependency('minitest', '~> 5.14')
76
+ s.add_runtime_dependency('gli','~> #{GLI::VERSION}')
77
77
  end
78
78
  EOS
79
79
  end
@@ -114,12 +114,6 @@ require 'rubygems'
114
114
  require 'rubygems/package_task'
115
115
  require 'rdoc/task'
116
116
  EOS
117
- if create_test_dir
118
- file.puts <<EOS
119
- require 'cucumber'
120
- require 'cucumber/rake/task'
121
- EOS
122
- end
123
117
  file.puts <<EOS
124
118
  Rake::RDocTask.new do |rd|
125
119
  rd.main = "README.rdoc"
@@ -134,44 +128,19 @@ end
134
128
  EOS
135
129
  if create_test_dir
136
130
  file.puts <<EOS
137
- CUKE_RESULTS = 'results.html'
138
- CLEAN << CUKE_RESULTS
139
- desc 'Run features'
140
- Cucumber::Rake::Task.new(:features) do |t|
141
- opts = "features --format html -o \#{CUKE_RESULTS} --format progress -x"
142
- opts += " --tags \#{ENV['TAGS']}" if ENV['TAGS']
143
- t.cucumber_opts = opts
144
- t.fork = false
145
- end
146
-
147
- desc 'Run features tagged as work-in-progress (@wip)'
148
- Cucumber::Rake::Task.new('features:wip') do |t|
149
- tag_opts = ' --tags ~@pending'
150
- tag_opts = ' --tags @wip'
151
- t.cucumber_opts = "features --format html -o \#{CUKE_RESULTS} --format pretty -x -s\#{tag_opts}"
152
- t.fork = false
153
- end
154
-
155
- task :cucumber => :features
156
- task 'cucumber:wip' => 'features:wip'
157
- task :wip => 'features:wip'
158
- EOS
159
- end
160
- if create_test_dir
161
- file.puts <<EOS
162
131
  require 'rake/testtask'
163
132
  Rake::TestTask.new do |t|
164
133
  t.libs << "test"
165
134
  t.test_files = FileList['test/*_test.rb']
166
135
  end
167
136
 
168
- task :default => [:test,:features]
137
+ task :default => :test
169
138
  EOS
170
139
  File.open("#{root_dir}/#{project_name}/test/default_test.rb",'w') do |test_file|
171
140
  test_file.puts <<EOS
172
- require 'test_helper'
141
+ require_relative "test_helper"
173
142
 
174
- class DefaultTest < Test::Unit::TestCase
143
+ class DefaultTest < Minitest::Test
175
144
 
176
145
  def setup
177
146
  end
@@ -188,15 +157,10 @@ EOS
188
157
  puts "Created #{root_dir}/#{project_name}/test/default_test.rb"
189
158
  File.open("#{root_dir}/#{project_name}/test/test_helper.rb",'w') do |test_file|
190
159
  test_file.puts <<EOS
191
- require 'test/unit'
160
+ require "minitest/autorun"
192
161
 
193
162
  # Add test libraries you want to use here, e.g. mocha
194
-
195
- class Test::Unit::TestCase
196
-
197
- # Add global extensions to the test case class here
198
-
199
- end
163
+ # Add helper classes or methods here, too
200
164
  EOS
201
165
  end
202
166
  puts "Created #{root_dir}/#{project_name}/test/test_helper.rb"
@@ -210,54 +174,6 @@ EOS
210
174
  bundler_file.puts "gemspec"
211
175
  end
212
176
  puts "Created #{root_dir}/#{project_name}/Gemfile"
213
- if create_test_dir
214
- features_dir = File.join(root_dir,project_name,'features')
215
- FileUtils.mkdir features_dir
216
- FileUtils.mkdir File.join(features_dir,"step_definitions")
217
- FileUtils.mkdir File.join(features_dir,"support")
218
- File.open(File.join(features_dir,"#{project_name}.feature"),'w') do |file|
219
- file.puts <<EOS
220
- Feature: My bootstrapped app kinda works
221
- In order to get going on coding my awesome app
222
- I want to have aruba and cucumber setup
223
- So I don't have to do it myself
224
-
225
- Scenario: App just runs
226
- When I get help for "#{project_name}"
227
- Then the exit status should be 0
228
- EOS
229
- end
230
- File.open(File.join(features_dir,"step_definitions","#{project_name}_steps.rb"),'w') do |file|
231
- file.puts <<EOS
232
- When /^I get help for "([^"]*)"$/ do |app_name|
233
- @app_name = app_name
234
- step %(I run `\#{app_name} help`)
235
- end
236
-
237
- # Add more step definitions here
238
- EOS
239
- end
240
- File.open(File.join(features_dir,"support","env.rb"),'w') do |file|
241
- file.puts <<EOS
242
- require 'aruba/cucumber'
243
-
244
- ENV['PATH'] = "\#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}\#{File::PATH_SEPARATOR}\#{ENV['PATH']}"
245
- LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
246
-
247
- Before do
248
- # Using "announce" causes massive warnings on 1.9.2
249
- @puts = true
250
- @original_rubylib = ENV['RUBYLIB']
251
- ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
252
- end
253
-
254
- After do
255
- ENV['RUBYLIB'] = @original_rubylib
256
- end
257
- EOS
258
- end
259
- puts "Created #{features_dir}"
260
- end
261
177
  end
262
178
 
263
179
  def self.mk_binfile(root_dir,create_ext_dir,force,dry_run,project_name,commands)
data/lib/gli/options.rb CHANGED
@@ -7,12 +7,12 @@ module GLI
7
7
 
8
8
  # Return the value of an attribute
9
9
  def[](k)
10
- @table[k.to_sym]
10
+ self.send(k.to_sym)
11
11
  end
12
12
 
13
13
  # Set the value of an attribute
14
14
  def[]=(k, v)
15
- @table[k.to_sym] = v
15
+ self.send("#{k.to_sym}=",v)
16
16
  end
17
17
 
18
18
  def map(&block)
data/lib/gli/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module GLI
2
2
  unless const_defined? :VERSION
3
- VERSION = '2.19.2'
3
+ VERSION = '2.20.0'
4
4
  end
5
5
  end
data/object-model.dot ADDED
@@ -0,0 +1,29 @@
1
+ digraph G {
2
+
3
+ rankdir="BT"
4
+ nodesep=0.5
5
+
6
+ node[shape=record fontname=courier fontsize=18]
7
+ edge[fontname=avenir fontsize=12]
8
+
9
+ CommandLineToken [ label="{ CommandLineToken | #name\l | #description\l | #long_description\l | #aliases\l}"]
10
+ CommandLineOption [ label="{ CommandLineOption | #default_value \l }"]
11
+ DSL
12
+ Command
13
+ Flag [ label="{ Flag | #argument_name\l }"]
14
+ Switch
15
+ App
16
+ TopLevel [ label="top level?" shape=diamond fontname=avenir fontsize=12]
17
+
18
+ Command -> DSL [ arrowhead=oarrow label=" includes" minlen=3]
19
+ Command -> CommandLineToken [ arrowhead=oarrow label="inherits"]
20
+ CommandLineOption -> CommandLineToken [ arrowhead=oarrow label="inherits"]
21
+ Flag -> CommandLineOption [ arrowhead=oarrow label="inherits"]
22
+ Switch -> CommandLineOption [ arrowhead=oarrow label="inherits"]
23
+ Command -> TopLevel [ arrowhead=none label="parent" style=dotted]
24
+ TopLevel -> App [ arrowhead=odiamond label="YES" style=dotted ]
25
+ TopLevel -> Command [ arrowhead=odiamond label="NO" style=dotted ]
26
+ CommandLineOption -> Command [ arrowhead=odiamond style=dotted label="associated_command"]
27
+
28
+ { rank=same; DSL; App }
29
+ }
data/object-model.png ADDED
Binary file
@@ -1,2 +1,2 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
  gemspec
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  # These would not be in a real GLI app; we do this so we can easily run this on the command line
4
- $: << File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','lib'))
4
+ $: << File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','..','lib'))
5
5
  $: << File.expand_path(File.join(File.dirname(__FILE__),'..','lib'))
6
6
 
7
7
  require 'gli'
@@ -0,0 +1,69 @@
1
+ require_relative "test_helper"
2
+ require "open3"
3
+
4
+ class GLICLITest < MiniTest::Test
5
+ include TestHelper
6
+
7
+ class AppHelp < GLICLITest
8
+ def test_running_with_no_options_produces_help
9
+ out = run_gli
10
+ assert_output_looks_like_help out
11
+ end
12
+
13
+ def test_running_with_help_command_produces_help
14
+ out = run_gli("help")
15
+ assert_output_looks_like_help out
16
+ end
17
+
18
+ def test_running_with_help_switch_produces_help
19
+ out = run_gli("--help")
20
+ assert_output_looks_like_help out
21
+ end
22
+
23
+ private
24
+
25
+ def assert_output_looks_like_help(out)
26
+ assert_match /gli - create scaffolding for a GLI-powered application/,out
27
+ assert_match /SYNOPSIS/,out
28
+ assert_match /GLOBAL OPTIONS/,out
29
+ assert_match /COMMANDS/,out
30
+ end
31
+
32
+ end
33
+
34
+ class Scaffolding < GLICLITest
35
+ def test_help_on_scaffold_command
36
+ out = run_gli("help scaffold")
37
+ assert_output_looks_like_help(out)
38
+ end
39
+ def test_help_on_scaffold_command_as_init
40
+ out = run_gli("help init")
41
+ assert_output_looks_like_help(out)
42
+ end
43
+
44
+ private
45
+
46
+ def assert_output_looks_like_help(out)
47
+ assert_match /init - Create a new GLI-based project/,out
48
+ assert_match /SYNOPSIS/,out
49
+ assert_match /COMMAND OPTIONS/,out
50
+ end
51
+ end
52
+
53
+ private
54
+
55
+ def run_gli(args="", return_err_and_status: false, expect_failure: false)
56
+ command_line_invocation = "bin/gli #{args}"
57
+ stdout_string, stderr_string, status = Open3.capture3(command_line_invocation)
58
+ if expect_failure
59
+ refute_equal 0,status.exitstatus,"Expected failure for '#{command_line_invocation}' but it succeeded"
60
+ else
61
+ assert_equal 0,status.exitstatus,"Expected success for '#{command_line_invocation}' but it failed"
62
+ end
63
+ if return_err_and_status
64
+ [ stdout_string, stderr_string, status ]
65
+ else
66
+ stdout_string
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,52 @@
1
+ require_relative "test_helper"
2
+ require "open3"
3
+
4
+ class GLIPoweredAppTest < MiniTest::Test
5
+ include TestHelper
6
+
7
+ def teardown
8
+ FileUtils.rm_f("todo.rdoc")
9
+ end
10
+
11
+ def test_help_works
12
+ out = run_app("help")
13
+ assert_top_level_help(out)
14
+ end
15
+
16
+ def test_unknown_command_exits_nonzero
17
+ out, err, status = run_app("asdfasdfasdf", expect_failure: true, return_err_and_status: true)
18
+ assert_match /Unknown command 'asdfasdfasdf'/,err
19
+ assert_equal 64, status.exitstatus
20
+ assert_top_level_help(out)
21
+ end
22
+
23
+ def test_unknown_switch_exits_nonzero
24
+ out, err, status = run_app("list --foo", expect_failure: true, return_err_and_status: true)
25
+ assert_match /Unknown option \-\-foo/,err
26
+ assert_equal 64, status.exitstatus
27
+ assert_match /COMMAND OPTIONS/, out
28
+ end
29
+
30
+ def test_missing_args_exits_nonzero
31
+ out, err, status = run_app("list", expect_failure: true, return_err_and_status: true)
32
+ assert_match /required_flag is required, required_flag2 is required/,err
33
+ assert_equal 64, status.exitstatus
34
+ assert_match /COMMAND OPTIONS/, out
35
+ end
36
+
37
+ def test_doc_generation
38
+ out, err, status = run_app("_doc", return_err_and_status: true)
39
+ assert File.exists?("todo.rdoc")
40
+ end
41
+
42
+ private
43
+ def assert_top_level_help(out)
44
+ assert_match /SYNOPSIS/, out
45
+ assert_match /GLOBAL OPTIONS/, out
46
+ assert_match /COMMANDS/, out
47
+ end
48
+
49
+ def run_app(args="", return_err_and_status: false, expect_failure: false)
50
+ run_command("test/apps/todo/bin/todo",args,return_err_and_status:return_err_and_status,expect_failure:expect_failure)
51
+ end
52
+ end
@@ -0,0 +1,30 @@
1
+ require_relative "test_helper"
2
+ require "open3"
3
+
4
+ class ScaffoldCommandTest < MiniTest::Test
5
+ include TestHelper
6
+
7
+ def test_scaffolded_app_has_reasonable_setup
8
+ FileUtils.rm_rf "scaffold_test"
9
+ run_gli("init scaffold_test")
10
+ assert Dir.exist? "scaffold_test"
11
+ FileUtils.chdir "scaffold_test" do
12
+ run_command("bundle install", "", return_err_and_status: false, expect_failure: false)
13
+
14
+ scaffold_lib = "lib:../lib"
15
+
16
+ # help works
17
+ out = run_command("bin/scaffold_test","--help", return_err_and_status: false, expect_failure: false, rubylib: scaffold_lib)
18
+ assert_match /SYNOPSIS/,out
19
+ assert_match /GLOBAL OPTIONS/,out
20
+ assert_match /COMMANDS/,out
21
+
22
+ # can run unit tests
23
+ out = run_command("bundle exec ","rake test", return_err_and_status: false, expect_failure: false, rubylib: scaffold_lib)
24
+ assert_match /0 failures/,out
25
+ assert_match /0 errors/,out
26
+ assert_match /0 skips/,out
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,52 @@
1
+ require "minitest/autorun"
2
+ require "pathname"
3
+ require "fileutils"
4
+
5
+ # Copied from https://github.com/splattael/minitest-around
6
+ # so as to avoid an explicit dependency
7
+ Minitest::Test.class_eval do
8
+ alias_method :run_without_around, :run
9
+ def run(*args)
10
+ if defined?(around)
11
+ result = nil
12
+ around { result = run_without_around(*args) }
13
+ result
14
+ else
15
+ run_without_around(*args)
16
+ end
17
+ end
18
+ end
19
+
20
+ module TestHelper
21
+ def around(&block)
22
+ Bundler.with_original_env do
23
+ root = Pathname(__FILE__).dirname / ".." / ".."
24
+ FileUtils.chdir root do
25
+ block.()
26
+ end
27
+ end
28
+ end
29
+
30
+ def run_gli(args="", return_err_and_status: false, expect_failure: false)
31
+ run_command("bin/gli",args,return_err_and_status:return_err_and_status,expect_failure:expect_failure)
32
+ end
33
+
34
+ def run_command(command,args,return_err_and_status:,expect_failure:,rubylib:nil)
35
+ command_line_invocation = "#{command} #{args}"
36
+ env = {}
37
+ if !rubylib.nil?
38
+ env["RUBYLIB"] = rubylib
39
+ end
40
+ stdout_string, stderr_string, status = Open3.capture3(env,command_line_invocation)
41
+ if expect_failure
42
+ refute_equal 0,status.exitstatus,"Expected failure for '#{command_line_invocation}' but it succeeded"
43
+ else
44
+ assert_equal 0,status.exitstatus,"Expected success for '#{command_line_invocation}' but it failed:\n#{stdout_string}\n\n#{stderr_string}\n\n"
45
+ end
46
+ if return_err_and_status
47
+ [ stdout_string, stderr_string, status ]
48
+ else
49
+ stdout_string
50
+ end
51
+ end
52
+ end