commandable 0.2.0.beta2 → 0.2.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
data/.gemrc ADDED
@@ -0,0 +1,8 @@
1
+ test_options:
2
+ auto_test_on_install: false
3
+ test_on_install: true
4
+ install_development_dependencies: true
5
+ test_development_dependencies: false
6
+ upload_results: true
7
+ force_install: false
8
+ force_uninstall_on_failure: false
File without changes
data/.gitignore CHANGED
@@ -5,4 +5,5 @@ pkg/*
5
5
  .DS_Store
6
6
  doc/**/*
7
7
  rdoc/**/*
8
- vendor/**/*
8
+ vendor/**/*
9
+ tmp/**/*
@@ -16,11 +16,12 @@ You can now "use your words" to let people interact with your apps in a natural
16
16
 
17
17
  ## Status
18
18
 
19
- 2011-03-18 - Final testing and building the example app. I'd wait to use it till I finish the example app. I'm finding new use cases as I do this and correcting some omissions of logic.
19
+ 2011-03-21 - Release Cadidate: 0.2.0.rc1
20
+
20
21
 
21
22
  ## Principle of Least Surprise
22
23
 
23
- I've tried to honestly follow the theory of the principle of least surprise so it should just work like you would expect it to.
24
+ I've tried to follow the principle of least surprise so Commandable should just work like you would expect it to. As long as you expect it to work the same way as I do.
24
25
 
25
26
  ## Requirements ##
26
27
 
@@ -171,23 +172,23 @@ One of the great features of **Commandable** is that it will automatically creat
171
172
 
172
173
  A typical help output looks something like this:
173
174
 
174
- Commandable - The easiest way to add command line control to your app.
175
- Copyrighted free software - Copyright (c) 2011 Mike Bethany.
176
- Version: 0.2.0.beta01
175
+ Commandable - The easiest way to add command line control to your app.
176
+ Copyrighted free software - Copyright (c) 2011 Mike Bethany.
177
+ Version: 0.2.0
177
178
 
178
- Usage: commandable <command> [parameters] [<command> [parameters]...]
179
+ Usage: commandable <command> [parameters] [<command> [parameters]...]
179
180
 
180
- Command Parameters Description
181
- error : Will raise a programmer error, not a user error
182
- so you see what happens when you have bad code
183
- examples [path] : Copies the test classes to a folder so
184
- you can see a bunch of small examples
185
- readme : displays the readme file (default)
186
- v : <xor> Application Version
187
- version : <xor> Application Version
188
- widget [path] : Copies a fully working app demonstrating how
189
- to use **Commandable** with RSpec and Cucumber
190
- help : you're looking at it now
181
+ Command Parameters Description
182
+ error : Will raise a programmer error, not a user error
183
+ so you see what happens when you have bad code
184
+ examples [path] : Copies the test classes to a folder so
185
+ you can see a bunch of small examples
186
+ readme : displays the readme file (default)
187
+ v : <xor> Application Version
188
+ version : <xor> Application Version
189
+ widget [path] : Copies a fully working app demonstrating how
190
+ to use Commandable with RSpec and Cucumber
191
+ help : you're looking at it now
191
192
 
192
193
 
193
194
 
@@ -198,7 +199,7 @@ For a fully working example with RSpec and Cucumber tests run this command:
198
199
 
199
200
  If you would like to see a bunch of simple classes that demonstrate its uses run:
200
201
 
201
- $ commandable example [path]
202
+ $ commandable examples [path]
202
203
 
203
204
  ### Commandable Options
204
205
 
@@ -251,8 +252,8 @@ Then you can do something like this:
251
252
  ###Color options
252
253
 
253
254
  **Commandable.color\_output**
254
- _default = false_
255
- Set to true to enable colorized help/usage instructions.
255
+ _default = true_
256
+ Set to false to disable colorized help/usage instructions. You might find it really, really annoying...
256
257
 
257
258
  **Commandable.color\_app\_info**
258
259
  _default = intense\_white_ + bold
@@ -347,7 +348,7 @@ If you need a little more control:
347
348
 
348
349
  end
349
350
 
350
- ### The easiest way
351
+ ### The even easier way
351
352
 
352
353
  **Commandable.execute(ARGV)**
353
354
 
@@ -363,7 +364,6 @@ Simply configure your bin file to run `Commandable#execute`:
363
364
 
364
365
  #!/usr/bin/env ruby
365
366
  $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
366
- require 'yourappname'
367
367
  require 'commandable'
368
368
  Commandable.verbose_parameters = false
369
369
  Commandable.color_output = true
@@ -373,6 +373,11 @@ Simply configure your bin file to run `Commandable#execute`:
373
373
  My App - It does stuff and things!
374
374
  Copyright (c) 2011 Acme Inc.
375
375
  """
376
+
377
+ # Make sure you require your app after Commandable, or use
378
+ # a configuration file to load the settings then your app
379
+ # See the Widget app for an example of this.
380
+ require 'yourappname'
376
381
  return_values = Commandable.execute(ARGV)
377
382
  # do stuff
378
383
 
@@ -383,18 +388,16 @@ I actually prefer to create a separate file for my **Commandable** configuration
383
388
 
384
389
  One really cool thing about this design is you can extend another app and add your own command line controls without having to crack open their code. The other app doesn't even have to use **Commandable**. You can just write your own methods that call the methods of the original program.
385
390
 
386
- I should also say the code is really, really ugly right now. Thats the very next thing I will be working on for this project. This is the "rough draft" version that works perfectly well but is very ugly code-wise. I needed to use it right now so am putting it out in beta.
391
+ I should also say the code is really, really ugly right now. Thats the very next thing I will be working on for this project. This is the "rough draft" version that works perfectly well but is very ugly code-wise. I needed to use it right now so am putting it out as is.
387
392
 
388
393
  If you have any questions about how the code works I've tried to give as much info in these docs as possible but I am also an OCD level commenter so you should be able to find fairly good explanations of what I'm doing in the code.
389
394
 
390
- Most of all it should be simple to use so if you have any problems please drop me a line. Also if you make any changes please send me a pull request. I hate people that don't respond to them, even to deny them, so I'm pretty good about that sort of thing.
395
+ Most of all it should be simple to use so if you have any problems please drop me a line. Also if you make any changes please send me a pull request. I when people that don't respond to them, even to deny them, so I'm pretty good about that sort of thing.
391
396
 
392
397
 
393
398
  ## To Do
394
399
 
395
- Still working on for this version:
396
-
397
- * Finish **Widget** example app. It will be in the release version but I want to release a beta so I can test the gem via RubyGems.
400
+ Done with 0.2.0. Release to final beta.
398
401
 
399
402
  ###Next version:
400
403
 
data/Rakefile CHANGED
@@ -1,29 +1,39 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
3
 
4
- require "rake"
5
- require "rake/rdoctask"
6
- require "rspec/core/rake_task"
4
+ require 'rake'
5
+ require 'rake/rdoctask'
6
+ require 'rspec/core/rake_task'
7
+ require 'cucumber/rake/task'
7
8
 
8
9
  desc "Run all examples"
9
10
  RSpec::Core::RakeTask.new(:spec) do |t|
10
11
  t.rspec_opts = %w[--color]
11
- t.verbose = false
12
+ t.verbose = true
12
13
  end
13
14
 
14
- task :default => [:spec, :build]
15
+ Cucumber::Rake::Task.new(:cucumber) do |t|
16
+ t.cucumber_opts = %w{--tags ~@jruby} unless defined?(JRUBY_VERSION)
17
+ end
18
+
19
+ task :default => [:test, :build]
20
+ task :test =>[:cucumber, :spec]
15
21
 
16
22
  task :clobber do
17
23
  rm_rf 'pkg'
18
24
  rm_rf 'tmp'
19
25
  rm_rf 'coverage'
26
+ rm_rf 'rdoc'
20
27
  end
21
28
 
22
29
  Rake::RDocTask.new do |rdoc|
23
30
  rdoc.rdoc_dir = 'rdoc'
24
- rdoc.title = "commandable #{Commandable::VERSION}"
31
+ rdoc.title = "Commandable #{Commandable::VERSION}"
25
32
  rdoc.rdoc_files.exclude('autotest/*')
33
+ rdoc.rdoc_files.exclude('features/*')
34
+ rdoc.rdoc_files.exclude('pkg/*')
26
35
  rdoc.rdoc_files.exclude('spec/**/*')
36
+ rdoc.rdoc_files.exclude('vendor/*')
27
37
  rdoc.rdoc_files.include('README*')
28
38
  rdoc.rdoc_files.include('lib/**/*.rb')
29
39
  end
@@ -8,7 +8,7 @@ Commandable.app_info =
8
8
  """
9
9
  \e[92mCommandable\e[0m - The easiest way to add command line control to your app.
10
10
  Copyrighted free software - Copyright (c) 2011 Mike Bethany.
11
- Version: #{Commandable::VERSION}
11
+ Version: #{Commandable::VERSION::STRING}
12
12
  """
13
13
 
14
14
  # App controller has to be loaded after commandable settings
@@ -5,18 +5,21 @@ require "commandable/version"
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "commandable"
7
7
  s.required_ruby_version = "~>1.9.2"
8
- s.version = Commandable::VERSION
8
+ s.version = Commandable::VERSION::STRING
9
9
  s.platform = Gem::Platform::RUBY
10
+ s.required_ruby_version = '>= 1.9.2'
10
11
  s.authors = ["Mike Bethany"]
11
12
  s.email = ["mikbe.tk@gmail.com"]
12
13
  s.homepage = "http://mikbe.tk"
13
14
  s.summary = %q{The easiest way to add command line control to your app.}
14
15
  s.description = %q{The easiest way to add command line control to your app.\nAdding command line control to your app is as easy as putting 'command "this command does xyz"' above a method.\nParameter lists and a help command are automatically built for you.}
16
+ s.license = 'MIT'
15
17
 
16
18
  s.add_dependency("term-ansicolor-hi", "~>1.0.7")
17
19
 
18
20
  s.add_development_dependency("rspec", "~>2.5")
19
- s.add_development_dependency("cucumber")
21
+ s.add_development_dependency("cucumber", "~>0.10")
22
+ s.add_development_dependency("aruba", "~>0.3")
20
23
 
21
24
  s.files = `git ls-files`.split("\n")
22
25
  s.test_files = `git ls-files -- {spec,autotest}/*`.split("\n")
@@ -0,0 +1,13 @@
1
+ Feature: Copy Examples
2
+ In order to learn how to use Commandable
3
+ As a developer
4
+ I want to look at some example files
5
+
6
+ Scenario: Copy example files from specs into the default directory
7
+ When I run `commandable examples`
8
+ Then a directory named "examples" should exist
9
+
10
+ Scenario: Copy example files from specs into a specified directory
11
+ When I run `commandable examples shazam`
12
+ Then a directory named "shazam" should exist
13
+
@@ -0,0 +1,18 @@
1
+ Feature: Download widget
2
+ In order to learn how to use Commandable by looking at a fully functional application
3
+ As a developer
4
+ I want to download the latest source code for Widget from Github
5
+
6
+ Background:
7
+ Given Git is installed
8
+
9
+ @download_widget
10
+ Scenario: Download widget from github into the default directory
11
+ When I run `commandable widget`
12
+ Then a directory named "widget" should exist
13
+
14
+ @download_widget
15
+ Scenario: Download widget from github into a specified directory
16
+ When I run `commandable widget potato`
17
+ Then a directory named "potato" should exist
18
+
@@ -1,3 +1,5 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
2
  require 'rspec/expectations'
3
+ require 'aruba/cucumber'
4
+ require 'fileutils'
3
5
  require 'commandable'
@@ -1,7 +1,15 @@
1
+ Before do
2
+ @aruba_timeout_seconds = 30
3
+ end
4
+
1
5
  When /^I run cucumber$/ do
2
- true.should be_true
6
+ # These are just to see color output is working
3
7
  end
4
8
 
5
9
  Then /^it doesn't give an error$/ do
6
- true.should be_true
10
+ # These are just to see color output is working
7
11
  end
12
+
13
+ Given /^Git is installed$/ do
14
+ raise Exception, "\n#{"ATTENION! " * 5}\nYou need git installed to run the Cucumber tests!\n\n" if `which git`.empty?
15
+ end
@@ -2,7 +2,8 @@ module Commandable
2
2
 
3
3
  # A helper to display the read me file and generate an example app
4
4
  class AppController
5
-
5
+ WIDGET_GITHUB ||= "://github.com/mikbe/widget"
6
+
6
7
  class << self
7
8
  extend Commandable
8
9
 
@@ -15,12 +16,33 @@ module Commandable
15
16
  command "Copies a fully working app demonstrating how\nto use Commandable with RSpec and Cucumber"
16
17
  # Creates a simple example app demonstrating a fully working app
17
18
  def widget(path="./widget")
18
- puts "This feature hasn't been added yet. I'm working on it now and it will be in the release version."
19
+ # Test for Git
20
+ unless git_installed?
21
+ puts "Git must be installed to download Widget (You're a developer and you don't have Git installed?)"
22
+ return
23
+ end
24
+ # Git already has all of it's own error trapping
25
+ # it would be horrible coupling and duplication
26
+ # of effort to do anything on my end for failures.
27
+ puts "\nUnable to download Widget. You can find the souce code here:\nhttps#{WIDGET_GITHUB}" unless download_widget(path) == 0
28
+ end
29
+
30
+ # Downloads Widget from the git repository
31
+ # This is external to the widget command so it can be stubbed for testing
32
+ def download_widget(path)
33
+ `git clone git#{WIDGET_GITHUB}.git #{path}`
34
+ $?.exitstatus
35
+ end
36
+
37
+ # Checks to see if Git is installed
38
+ # This is external to the widget command so it can be stubbed for testing
39
+ def git_installed?
40
+ !`git --version`.chomp.match(/^git version/i).nil?
19
41
  end
20
42
 
21
43
  command "Copies the test classes to a folder so\nyou can see a bunch of small examples"
22
44
  # Copies the test classes to a folder so you can see a bunch of small examples
23
- def examples(path="./example_classes")
45
+ def examples(path="./examples")
24
46
  FileUtils.copy_dir(File.expand_path(File.dirname(__FILE__) + '/../../spec/source_code_examples'),path)
25
47
  end
26
48
 
@@ -222,9 +222,9 @@ module Commandable
222
222
  # Set colors to their default values
223
223
  def reset_colors
224
224
  # Colors - off by default
225
- @color_output ||= false
225
+ @color_output ||= true
226
226
  # Build the default colors
227
- Term::ANSIColorHI.coloring = true
227
+ Term::ANSIColorHI.coloring = color_output
228
228
  c = Term::ANSIColorHI
229
229
  @color_app_info = c.intense_white + c.bold
230
230
  @color_app_name = c.intense_green + c.bold
@@ -1,4 +1,12 @@
1
1
  module Commandable
2
- # The application's version number
3
- VERSION = "0.2.0.beta2"
4
- end
2
+ module VERSION # :nodoc:
3
+ MAJOR = 0
4
+ MINOR = 2
5
+ TINY = 0
6
+ PRE = "rc1"
7
+
8
+ STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
9
+
10
+ SUMMARY = "Commandable #{STRING}"
11
+ end
12
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe Commandable do
4
+
5
+ before(:each) {
6
+ Commandable.reset_all
7
+ Commandable.color_output = true
8
+ Commandable.verbose_parameters = false
9
+ Commandable.app_name = "commandable"
10
+ Commandable.app_info =
11
+ """
12
+ \e[92mCommandable\e[0m - The easiest way to add command line control to your app.
13
+ Copyrighted free software - Copyright (c) 2011 Mike Bethany.
14
+ Version: #{Commandable::VERSION::STRING}
15
+ """
16
+
17
+ # App controller has to be loaded after commandable settings
18
+ # or it won't be able to use the settings
19
+ load 'commandable/app_controller.rb'
20
+ }
21
+
22
+ context "when running the widget command" do
23
+
24
+ context "when git isn't installed" do
25
+
26
+ it "should inform them they need Git" do
27
+ Commandable::AppController.stub(:git_installed?){false}
28
+ execute_output_s(["widget"]).should match(/Git must be installed/)
29
+ end
30
+
31
+ end
32
+ context "when git is installed" do
33
+
34
+ context "and it's able to install the files" do
35
+ it "should download Widget from github" do
36
+ Commandable::AppController.stub(:download_widget){0}
37
+ execute_output_s(["widget"]).should_not include("Unable to download")
38
+ end
39
+ end
40
+
41
+ context "but it's not able to install the files" do
42
+ it "should download Widget from github" do
43
+ Commandable::AppController.stub(:download_widget){1}
44
+ execute_output_s(["widget"]).should include("Unable to download")
45
+ end
46
+ end
47
+
48
+
49
+ end
50
+
51
+
52
+ end
53
+
54
+ end
@@ -6,10 +6,10 @@ describe Commandable do
6
6
  Commandable.reset_all
7
7
  Commandable.app_name = "mycoolapp"
8
8
  Commandable.app_info =
9
- """
10
- My Cool App - It does stuff and things!
11
- Copyright (c) 2011 Acme Inc.
12
- """
9
+ """
10
+ My Cool App - It does stuff and things!
11
+ Copyright (c) 2011 Acme Inc.
12
+ """
13
13
 
14
14
  load 'parameter_class.rb'
15
15
  }
@@ -49,6 +49,7 @@ describe Commandable do
49
49
  end
50
50
 
51
51
  it "adds the application name to the help output if it's given" do
52
+ Commandable.color_output = false
52
53
  load 'parameter_class.rb'
53
54
  Commandable.app_name = "mycoolapp"
54
55
  Commandable.help.to_s.should match(/Usage: mycoolapp <command>/)
@@ -5,8 +5,10 @@ $:.unshift File.expand_path(File.dirname(__FILE__))
5
5
 
6
6
  require 'pp'
7
7
  require 'term/ansicolor'
8
+ require 'rspec/mocks'
8
9
  require 'rspec'
9
10
  require 'commandable'
11
+ #require 'commandable/app_controller'
10
12
 
11
13
  # A note on the specs:
12
14
  # Since Commandable uses singletons the tests sometimes get confused about their state.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commandable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.beta2
4
+ version: 0.2.0.rc1
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: term-ansicolor-hi
17
- requirement: &2154879100 !ruby/object:Gem::Requirement
17
+ requirement: &2156630780 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 1.0.7
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2154879100
25
+ version_requirements: *2156630780
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rspec
28
- requirement: &2154878600 !ruby/object:Gem::Requirement
28
+ requirement: &2156630320 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,18 +33,29 @@ dependencies:
33
33
  version: '2.5'
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *2154878600
36
+ version_requirements: *2156630320
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: cucumber
39
- requirement: &2154878200 !ruby/object:Gem::Requirement
39
+ requirement: &2156629860 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
- - - ! '>='
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: '0.10'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *2156629860
48
+ - !ruby/object:Gem::Dependency
49
+ name: aruba
50
+ requirement: &2156629400 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
43
54
  - !ruby/object:Gem::Version
44
- version: '0'
55
+ version: '0.3'
45
56
  type: :development
46
57
  prerelease: false
47
- version_requirements: *2154878200
58
+ version_requirements: *2156629400
48
59
  description: The easiest way to add command line control to your app.\nAdding command
49
60
  line control to your app is as easy as putting 'command "this command does xyz"'
50
61
  above a method.\nParameter lists and a help command are automatically built for
@@ -56,17 +67,20 @@ executables:
56
67
  extensions: []
57
68
  extra_rdoc_files: []
58
69
  files:
70
+ - .gemrc
71
+ - .gemtest
59
72
  - .gitignore
60
73
  - BUGS.txt
61
74
  - Gemfile
62
75
  - LICENCE
63
76
  - README.markdown
64
77
  - Rakefile
65
- - _testing/alias_trap.rb
66
78
  - autotest/discover.rb
67
79
  - bin/commandable
68
80
  - commandable.gemspec
69
81
  - features/ansicolor.feature
82
+ - features/copy_examples.feature
83
+ - features/download_widget.feature
70
84
  - features/setup/env.rb
71
85
  - features/step-definitions/step-definitions.rb
72
86
  - lib/commandable.rb
@@ -75,6 +89,7 @@ files:
75
89
  - lib/commandable/exceptions.rb
76
90
  - lib/commandable/version.rb
77
91
  - lib/monkey_patch/file_utils.rb
92
+ - spec/commandable/app_controller_spec.rb
78
93
  - spec/commandable/command_line_execution_spec.rb
79
94
  - spec/commandable/commandable_spec.rb
80
95
  - spec/commandable/help_generator_spec.rb
@@ -104,7 +119,8 @@ files:
104
119
  - spec/spec_helper.rb
105
120
  has_rdoc: true
106
121
  homepage: http://mikbe.tk
107
- licenses: []
122
+ licenses:
123
+ - MIT
108
124
  post_install_message:
109
125
  rdoc_options: []
110
126
  require_paths:
@@ -112,7 +128,7 @@ require_paths:
112
128
  required_ruby_version: !ruby/object:Gem::Requirement
113
129
  none: false
114
130
  requirements:
115
- - - ~>
131
+ - - ! '>='
116
132
  - !ruby/object:Gem::Version
117
133
  version: 1.9.2
118
134
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -129,6 +145,7 @@ specification_version: 3
129
145
  summary: The easiest way to add command line control to your app.
130
146
  test_files:
131
147
  - autotest/discover.rb
148
+ - spec/commandable/app_controller_spec.rb
132
149
  - spec/commandable/command_line_execution_spec.rb
133
150
  - spec/commandable/commandable_spec.rb
134
151
  - spec/commandable/help_generator_spec.rb
@@ -1,14 +0,0 @@
1
- require 'pp'
2
- # hash1 = {
3
- # :c=>{:foo=>"a c command", :description=>"c description"},
4
- # :a=>{:foo=>"z a command", :description=>"c description"},
5
- # :b=>{:foo=>" buh command", :description=>"c description"}
6
- # }
7
-
8
- hash1 = [
9
- {:foo=>"a c command", :description=>"c description"},
10
- {:foo=>"z a command", :description=>"c description"},
11
- {:foo=>" buh command", :description=>"c description"}
12
- ]
13
-
14
- puts hash1.shift[:foo]