git-style-binaries 0.1.11 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,7 +13,7 @@ This gem uses [`trollop`](http://trollop.rubyforge.org/) for option parsing
13
13
 
14
14
  Checkout <a href="http://www.xcombinator.com/movies/git-style-binaries.mov">the new screencast!</a>
15
15
 
16
- <a href="http://www.xcombinator.com/movies/git-style-binaries.mov"><img src="http://github.com/jashmenn/git-style-binaries/tree/master/doc/gsb-screencast.png?raw=true" width='880' height='784' border=0></a>
16
+ <a href="http://www.xcombinator.com/movies/git-style-binaries.mov"><img src="https://raw.github.com/jashmenn/git-style-binaries/master/doc/gsb-screencast.png" width='880' height='784' border=0></a>
17
17
 
18
18
  ## Try it out
19
19
 
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ begin
13
13
  gem.homepage = "http://github.com/jashmenn/git-style-binaries"
14
14
  gem.authors = ["Nate Murray"]
15
15
  gem.add_dependency 'trollop'
16
- gem.add_dependency 'shoulda' # for running the tests
16
+ gem.add_development_dependency 'shoulda' # for running the tests
17
17
 
18
18
  excludes = /(README\.html)/
19
19
  gem.files = (FileList["[A-Z]*.*", "{bin,examples,generators,lib,rails,spec,test,vendor}/**/*", 'Rakefile', 'LICENSE*']).delete_if{|f| f =~ excludes}
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 10
2
+ :patch: 11
3
3
  :major: 0
4
4
  :minor: 1
@@ -1,8 +1,9 @@
1
1
  class Object
2
- def returning(value)
3
- yield(value)
4
- value
5
- end unless Object.respond_to?(:returning)
2
+ # ruby 1.8.6 backport of tap
3
+ def tap
4
+ yield(self)
5
+ self
6
+ end unless Object.respond_to?(:tap)
6
7
  end
7
8
 
8
9
  class Symbol
@@ -1,19 +1,6 @@
1
1
  $:.unshift(File.dirname(__FILE__))
2
2
  require 'rubygems'
3
-
4
- # Load the vendor gems
5
- $:.unshift(File.dirname(__FILE__) + "/../vendor/gems")
6
- %w(trollop).each do |library|
7
- begin
8
- require "#{library}/lib/#{library}"
9
- rescue LoadError
10
- begin
11
- require 'trollop'
12
- rescue LoadError
13
- puts "There was an error loading #{library}. Try running 'gem install #{library}' to correct the problem"
14
- end
15
- end
16
- end
3
+ require 'trollop'
17
4
 
18
5
  require 'ext/core'
19
6
  require 'ext/colorize'
@@ -21,7 +8,7 @@ require 'git-style-binary/autorunner'
21
8
  Dir[File.dirname(__FILE__) + "/git-style-binary/helpers/*.rb"].each {|f| require f}
22
9
 
23
10
  module GitStyleBinary
24
-
11
+
25
12
  class << self
26
13
  include Helpers::NameResolver
27
14
  attr_accessor :current_command
@@ -47,7 +34,7 @@ module GitStyleBinary
47
34
  def load_primary
48
35
  unless @loaded_primary
49
36
  @loaded_primary = true
50
- primary_file = File.join(binary_directory, basename)
37
+ primary_file = File.join(binary_directory, basename)
51
38
  load primary_file
52
39
 
53
40
  if !GitStyleBinary.primary_command # you still dont have a primary load a default
@@ -76,7 +63,7 @@ module GitStyleBinary
76
63
 
77
64
  # UGLY eek
78
65
  attr_accessor :name_of_command_being_loaded
79
-
66
+
80
67
  end
81
68
  end
82
69
 
@@ -2,19 +2,22 @@ require 'git-style-binary'
2
2
 
3
3
  module GitStyleBinary
4
4
  def self.command(&block)
5
- returning Command.new(:constraints => [block]) do |c|
6
- c.name ||= (GitStyleBinary.name_of_command_being_loaded || GitStyleBinary.current_command_name)
5
+ Command.new(:constraints => [block]).tap do |c|
6
+ c.name ||= (GitStyleBinary.name_of_command_being_loaded ||
7
+ GitStyleBinary.current_command_name)
7
8
  GitStyleBinary.known_commands[c.name] = c
8
9
 
9
- if !GitStyleBinary.current_command || GitStyleBinary.current_command.is_primary?
10
+ if !GitStyleBinary.current_command ||
11
+ GitStyleBinary.current_command.is_primary?
10
12
  GitStyleBinary.current_command = c
11
13
  end
12
14
  end
13
15
  end
14
16
 
15
17
  def self.primary(&block)
16
- returning Primary.new(:constraints => [block]) do |c|
17
- c.name ||= (GitStyleBinary.name_of_command_being_loaded || GitStyleBinary.current_command_name)
18
+ Primary.new(:constraints => [block]).tap do |c|
19
+ c.name ||= (GitStyleBinary.name_of_command_being_loaded ||
20
+ GitStyleBinary.current_command_name)
18
21
  GitStyleBinary.known_commands[c.name] = c
19
22
 
20
23
  GitStyleBinary.primary_command = c unless GitStyleBinary.primary_command
@@ -55,7 +58,7 @@ module GitStyleBinary
55
58
  end
56
59
 
57
60
  def parser
58
- @parser ||= begin
61
+ @parser ||= begin
59
62
  p = Parser.new
60
63
  p.command = self
61
64
  p
@@ -67,11 +70,11 @@ module GitStyleBinary
67
70
  end
68
71
 
69
72
  def run
70
- GitStyleBinary.load_primary unless is_primary?
73
+ GitStyleBinary.load_primary unless is_primary?
71
74
  GitStyleBinary.load_subcommand if is_primary? && running_subcommand?
72
75
  load_all_parser_constraints
73
76
  @opts = process_args_with_subcmd
74
- call_parser_run_block
77
+ call_parser_run_block
75
78
  self
76
79
  end
77
80
 
@@ -96,23 +99,24 @@ module GitStyleBinary
96
99
  parser.consume_all(GitStyleBinary.primary_command.constraints)
97
100
  end
98
101
 
99
- def load_parser_local_constraints
102
+ def load_parser_local_constraints
100
103
  cur = GitStyleBinary.current_command # see, why isn't 'this' current_command?
101
104
 
102
105
  unless self.is_primary? && cur == self
103
- # TODO TODO - the key lies in this function. figure out when you hav emore engergy
104
- # soo UGLY. see #process_parser! unify with that method
105
- # parser.consume_all(constraints) rescue ArgumentError
106
+ # TODO - the key lies in this function. figure out when you
107
+ # have more energy soo UGLY. see #process_parser! unify with
108
+ # that method parser.consume_all(constraints) rescue
109
+ # ArgumentError
106
110
  parser.consume_all(cur.constraints)
107
111
  end
108
112
  end
109
113
 
110
114
  def call_parser_run_block
111
115
  runs = GitStyleBinary.current_command.parser.runs
112
-
116
+
113
117
  parser.run_callbacks(:before_run, self)
114
118
  parser.runs.last.call(self) # ... not too happy with this
115
- parser.run_callbacks(:after_run, self)
119
+ parser.run_callbacks(:after_run, self)
116
120
  end
117
121
 
118
122
  def process_args_with_subcmd(args = ARGV, *a, &b)
@@ -124,7 +128,7 @@ module GitStyleBinary
124
128
 
125
129
  # TOOooootally ugly! why? bc load_parser_local_constraints doesn't work
126
130
  # when loading the indivdual commands because it depends on
127
- # #current_command. This really sucks and is UGLY.
131
+ # #current_command. This really sucks and is UGLY.
128
132
  # the todo is to put in 'load_all_parser_constraints' and this works
129
133
  def process_parser!
130
134
  # load_all_parser_constraints
@@ -135,10 +139,10 @@ module GitStyleBinary
135
139
  parser.consume_all(constraints)
136
140
 
137
141
  # hack
138
- parser.consume {
142
+ parser.consume {
139
143
  opt :version, "Print version and exit" if @version unless @specs[:version] || @long["version"]
140
144
  opt :help, "Show this message" unless @specs[:help] || @long["help"]
141
- resolve_default_short_options
145
+ resolve_default_short_options!
142
146
  } # hack
143
147
  end
144
148
 
@@ -170,7 +174,7 @@ module GitStyleBinary
170
174
  parser.leftovers
171
175
  end
172
176
 
173
- def short_desc
177
+ def short_desc
174
178
  parser.short_desc
175
179
  end
176
180
 
@@ -179,12 +183,18 @@ module GitStyleBinary
179
183
  GitStyleBinary.primary_name == name ? GitStyleBinary.primary_name : GitStyleBinary.primary_name + "-" + name
180
184
  end
181
185
 
186
+ # die basically ripped out of trollop, because it can't be called
187
+ # without first calling 'Trollop.options'
182
188
  def die arg, msg=nil
183
- p = parser # create local copy
184
- Trollop.instance_eval { @p = p }
185
- Trollop::die(arg, msg)
189
+ if msg
190
+ $stderr.puts "Error: #{arg} - #{msg}."
191
+ else
192
+ $stderr.puts "Error: #{arg}."
193
+ end
194
+ $stderr.puts "Try --help for help."
195
+ exit(-1)
186
196
  end
187
-
197
+
188
198
  # Helper to return the option
189
199
  def [](k)
190
200
  opts[k]
@@ -6,16 +6,19 @@ GitStyleBinary.command do
6
6
  short_desc "create a blog post"
7
7
  banner <<-EOS
8
8
  SYNOPSIS
9
- #{command.full_name} #{all_options_string} {content|STDIN}
9
+ #{command.full_name} #{all_options_string} {content|STDIN}
10
10
 
11
11
  EOS
12
12
  opt :blog, "short name of the blog to use", :default => 'default'
13
- opt :category, "tag/category. specify multiple times for multiple categories", :type => String, :multi => true
13
+ opt :category, "tag/category. specify multiple times for multiple categories",
14
+ :type => String, :multi => true
14
15
  opt :title, "title for the post", :required => true, :type => String
15
- opt :type, "type of the content [html|xhtml|text]", :default => 'html', :type => String
16
+ opt :type, "type of the content [html|xhtml|text]",
17
+ :default => 'html', :type => String
16
18
 
17
19
  run do |command|
18
- command.die :type, "type must be one of [html|xhtml|text]" unless command.opts[:type] =~ /^(x?html|text)$/i
20
+ command.die :type, "type must be one of [html|xhtml|text]" unless
21
+ command.opts[:type] =~ /^(x?html|text)$/i
19
22
 
20
23
  puts "Subcommand name: #{command.name.inspect}"
21
24
  puts "Options: #{command.opts.inspect}"
@@ -62,7 +62,7 @@ class RunningBinariesTest < Test::Unit::TestCase
62
62
  end
63
63
  should "be able to require 'primary' and run just fine"
64
64
  end
65
-
65
+
66
66
  context "when running with an action" do
67
67
  # should be the same for both formats
68
68
  ["wordpress-categories", "wordpress categories"].each do |bin_format|
@@ -77,7 +77,7 @@ class RunningBinariesTest < Test::Unit::TestCase
77
77
  end
78
78
  end
79
79
  end
80
-
80
+
81
81
  context "callbacks" do
82
82
  context "on a binary" do
83
83
  setup { @stdout, @stderr = bin("wordpress") }
@@ -86,9 +86,9 @@ class RunningBinariesTest < Test::Unit::TestCase
86
86
  should "run the callback #{time}_run}" do
87
87
  assert @stdout.match(/#{time}_run command/)
88
88
  end
89
- end
89
+ end
90
90
  end
91
-
91
+
92
92
  context "on help" do
93
93
  setup { @stdout, @stderr = bin("wordpress -h") }
94
94
 
@@ -96,11 +96,11 @@ class RunningBinariesTest < Test::Unit::TestCase
96
96
  should "not run the callback #{time}_run" do
97
97
  assert_nil @stdout.match(/#{time}_run command/)
98
98
  end
99
- end
99
+ end
100
100
  end
101
-
101
+
102
102
  end
103
-
103
+
104
104
 
105
105
  context "when running the subcommand" do
106
106
  # should be the same for both formats
@@ -110,7 +110,7 @@ class RunningBinariesTest < Test::Unit::TestCase
110
110
  context "with no options" do
111
111
  setup { @stdout, @stderr = bin("#{bin_format}") }
112
112
  should "fail because title is required" do
113
- output_matches /Error: option 'title' must be specified.\s*Try --help for help/m
113
+ output_matches /Error: option --title must be specified.\s*Try --help for help/m
114
114
  end
115
115
  end
116
116
 
@@ -136,7 +136,7 @@ class RunningBinariesTest < Test::Unit::TestCase
136
136
  setup { @stdout, @stderr = bin("#{bin_format} --title='glendale' --type=yaml") }
137
137
 
138
138
  should "die on invalid options" do
139
- output_matches /argument \-\-type type must be one of \[html\|xhtml\|text\]/
139
+ output_matches /type must be one of \[html\|xhtml\|text\]/
140
140
  end
141
141
  end
142
142
 
@@ -144,9 +144,9 @@ class RunningBinariesTest < Test::Unit::TestCase
144
144
  end # end #each
145
145
  end
146
146
 
147
- ["wordpress help post", "wordpress post -h"].each do |format|
147
+ ["wordpress help post", "wordpress post -h"].each do |format|
148
148
  context "when calling '#{format}'" do
149
-
149
+
150
150
  setup { @stdout, @stderr = bin(format) }
151
151
  should "have a description" do
152
152
  output_matches /create a blog post/
metadata CHANGED
@@ -1,46 +1,55 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: git-style-binaries
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.11
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
5
6
  platform: ruby
6
- authors:
7
+ authors:
7
8
  - Nate Murray
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
-
12
- date: 2010-02-04 00:00:00 -08:00
13
- default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2010-02-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: trollop
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
17
22
  type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
24
- version:
25
- - !ruby/object:Gem::Dependency
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
26
31
  name: shoulda
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
27
38
  type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: "0"
34
- version:
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
35
46
  description: Ridiculously easy git-style binaries
36
47
  email: nate@natemurray.com
37
48
  executables: []
38
-
39
49
  extensions: []
40
-
41
- extra_rdoc_files:
50
+ extra_rdoc_files:
42
51
  - README.markdown
43
- files:
52
+ files:
44
53
  - README.markdown
45
54
  - Rakefile
46
55
  - VERSION.yml
@@ -64,35 +73,32 @@ files:
64
73
  - test/running_binaries_test.rb
65
74
  - test/shoulda_macros/matching_stdio.rb
66
75
  - test/test_helper.rb
67
- has_rdoc: true
68
76
  homepage: http://github.com/jashmenn/git-style-binaries
69
77
  licenses: []
70
-
71
78
  post_install_message:
72
- rdoc_options:
79
+ rdoc_options:
73
80
  - --charset=UTF-8
74
- require_paths:
81
+ require_paths:
75
82
  - lib
76
- required_ruby_version: !ruby/object:Gem::Requirement
77
- requirements:
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- version: "0"
81
- version:
82
- required_rubygems_version: !ruby/object:Gem::Requirement
83
- requirements:
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- version: "0"
87
- version:
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
88
95
  requirements: []
89
-
90
96
  rubyforge_project:
91
- rubygems_version: 1.3.5
97
+ rubygems_version: 1.8.24
92
98
  signing_key:
93
99
  specification_version: 3
94
100
  summary: Add git-style binaries to your project easily.
95
- test_files:
101
+ test_files:
96
102
  - test/git-style-binary/command_test.rb
97
103
  - test/git_style_binary_test.rb
98
104
  - test/running_binaries_test.rb