greenhouse 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb09c160cfae667639e3d36d4ac008e47dcbd7fd
4
- data.tar.gz: a20696bc130d382de9b591e2336f34f5f943d667
3
+ metadata.gz: e392ae36dc3e9abf2e9cabffc067e27418633b31
4
+ data.tar.gz: 935734f05718a35a1e701c9ae7cd5c6535b80aff
5
5
  SHA512:
6
- metadata.gz: 04f751c5e720212da0918a2868bbc727083295bb96e61eb8613d3ecec9c8c133567a9cf4f2b80fe05b9072f032993f74e8ef7652bb3dcda9709445c5eb425dea
7
- data.tar.gz: 0bccfedd895e135bce4ecd184349b6275d9f0f0e33b932177e67336d706e1d2c774fd8eb67c73c61421ab026cebd553cfda7ce8db10a2c4c86af91e1b8868fcb
6
+ metadata.gz: 6bb6c93fcb847fa5833c39a41d6452dd33572225aaf1ae33fd0f8a79d67e8720517435eaccec8f8ec0d240f8c65e509d5c0ed9aa5ed66ac18c4298db7c08bf07
7
+ data.tar.gz: 6647ec4bf8a6116c6363be50aed4890bc6f943c1659d50c13355c20c500f9bb4aeab1a4c62ec308ec146974237318849ffa0ea508783057cc0832fd8dcb82452
@@ -2,19 +2,10 @@ module Greenhouse
2
2
  class CLI
3
3
  include Scripts::Script
4
4
 
5
- valid_arguments("-v")
5
+ valid_argument Scripts::Argument.new("-v, --verbose", :valid => [], :summary => "Output additional information from command executions to STDOUT")
6
6
 
7
- def self.verbose
8
- @verbose || false
9
- end
10
-
11
7
  def self.verbose?
12
- verbose == true
13
- end
14
-
15
- def self.verbose=(v)
16
- @verbose = v
17
- @verbose
8
+ user_arguments.map(&:key).include?("-v")
18
9
  end
19
10
 
20
11
  def self.exec(cmd)
@@ -25,13 +16,13 @@ module Greenhouse
25
16
  end
26
17
  end
27
18
 
28
- def self.arguments(*args)
19
+ def self.add_arguments(*args)
29
20
  keep = []
30
21
  args.each_with_index do |arg,a|
31
22
  if Commands::exists?(arg)
32
23
  begin
33
24
  @command = Commands::command(arg)
34
- @command.arguments(*args.slice(a+1,args.length-a))
25
+ @command.set_arguments(*args.slice(a+1,args.length-a))
35
26
  rescue Scripts::InvalidArgument => e
36
27
  puts e.message
37
28
  Commands::command(arg).usage
@@ -39,6 +30,7 @@ module Greenhouse
39
30
  end
40
31
  break
41
32
  end
33
+
42
34
  keep << arg
43
35
  end
44
36
  super(*keep)
@@ -67,14 +59,18 @@ module Greenhouse
67
59
  def self.usage
68
60
  puts <<USAGE
69
61
  #{binary} v#{version}
62
+
70
63
  usage: #{binary} #{valid_arguments.to_s} <command> [<args>]
71
-
64
+
65
+ Arguments:
66
+ #{valid_arguments.to_help}
67
+
72
68
  The available greenhouse commands are:
73
69
  USAGE
74
70
 
75
71
  Commands::commands.each do |cmd|
76
72
  print " %-#{Commands::commands.sort { |a,b| a.command_name.length <=> b.command_name.length }.last.command_name.length + 2}s" % cmd.command_name
77
- puts cmd.command_summary
73
+ puts "# #{cmd.command_summary}"
78
74
  end
79
75
 
80
76
  puts
@@ -82,12 +78,19 @@ USAGE
82
78
  end
83
79
 
84
80
  def self.start
85
- arguments(*ARGV)
86
- verbose = arguments.map(&:key).include?("-v")
87
-
81
+ begin
82
+ set_arguments(*ARGV)
83
+ rescue Scripts::InvalidArgument => e
84
+ puts e.message
85
+ return
86
+ rescue Exception => e
87
+ usage
88
+ return
89
+ end
90
+
88
91
  if @command.nil?
89
92
  usage
90
- exit 1
93
+ return
91
94
  end
92
95
 
93
96
  @command.run
@@ -28,6 +28,8 @@ require 'greenhouse/commands/console'
28
28
  require 'greenhouse/commands/push'
29
29
  require 'greenhouse/commands/pull'
30
30
  require 'greenhouse/commands/sync'
31
+ require 'greenhouse/commands/bundle'
32
+ require 'greenhouse/commands/specs'
31
33
  require 'greenhouse/commands/purge'
32
34
  require 'greenhouse/commands/remove'
33
35
  require 'greenhouse/commands/help'
@@ -0,0 +1,46 @@
1
+ module Greenhouse
2
+ module Commands
3
+ class Bundle
4
+ include Command
5
+ command_summary "Run bundler for one or all of your projects"
6
+ valid_arguments Scripts::Argument.new("install", summary: "Install the gems specified by the Gemfile or Gemfile.lock"), Scripts::Argument.new("update", summary: "Update dependencies to their latest versions")
7
+ project_arguments *Projects::projects.map(&:to_arg)
8
+
9
+ class << self
10
+ def usage
11
+ puts <<USAGE
12
+ usage: #{::Greenhouse::CLI.command_name} #{command_name} <#{valid_arguments.map(&:key).join(", ")}> [<project>]
13
+
14
+ Arguments:
15
+ #{valid_arguments.to_help}
16
+
17
+ Projects:
18
+ #{project_arguments.to_help}
19
+ USAGE
20
+ end
21
+ end
22
+
23
+ def bundle_all(cmd)
24
+ Projects::projects.each do |project|
25
+ Tasks::BundleProject.perform(project, cmd)
26
+ end
27
+ end
28
+
29
+ def bundle_project(project, cmd)
30
+ Tasks::BundleProject.perform(project, cmd)
31
+ end
32
+
33
+ def run
34
+ cmd = arguments.select { |arg| valid_arguments.map(&:key).include?(arg.key) }.first
35
+ if cmd.nil?
36
+ puts "Please specify a bundle command."
37
+ usage
38
+ return
39
+ end
40
+
41
+ project = Projects::projects.select { |project| arguments.map(&:key).include?(project.name) }.first
42
+ project.nil? ? bundle_all(cmd) : bundle_project(project, cmd)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -20,6 +20,7 @@ module Greenhouse
20
20
  @command_summary = summary unless summary.nil?
21
21
  @command_summary
22
22
  end
23
+ alias_method :summary, :command_summary
23
24
 
24
25
  def usage
25
26
  puts "usage: #{::Greenhouse::CLI.command_name} #{command_name} #{valid_arguments.to_s}"
@@ -34,7 +35,7 @@ module Greenhouse
34
35
  rescue Exception => e
35
36
  puts e.message
36
37
  @command.usage if e.is_a?(Scripts::InvalidArgument)
37
- exit 1
38
+ return
38
39
  end
39
40
  end
40
41
 
@@ -0,0 +1,13 @@
1
+ module Greenhouse
2
+ module Commands
3
+ class Specs
4
+ include Command
5
+ command_summary "Not Yet Implemented"
6
+
7
+ def run
8
+ puts "Not Yet Implemented"
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -2,13 +2,17 @@ module Greenhouse
2
2
  module Commands
3
3
  class Status
4
4
  include Command
5
- command_summary "List projects and their current status"
6
- valid_arguments Scripts::Argument.new("-v, --verbose", :summary => "Print out detailed information about project status (local changes, ahead/behind/diverged branches, etc.)")
5
+ summary "List projects and their current status"
6
+ valid_argument Scripts::Argument.new("-g, --git", :summary => "Check git remotes and print out verbose information about project git status")
7
+ valid_argument Scripts::Argument.new("--all", :summary => "Print status for all projects (default)")
8
+ valid_argument Scripts::Argument.new("--apps", :summary => "Print status for all applications")
9
+ valid_argument Scripts::Argument.new("--gems", :summary => "Print status for all gems")
10
+ # TODO move engine to ForthRail
11
+ #valid_argument Scripts::Argument.new("--engine", :summary => "Print status for the Forth Rail Engine")
7
12
  project_arguments *Projects::projects.map(&:to_arg)
8
13
 
9
- class << self
10
- def usage
11
- puts <<USAGE
14
+ def self.usage
15
+ puts <<USAGE
12
16
  usage: #{::Greenhouse::CLI.command_name} #{command_name} [<project>] #{valid_arguments.to_s}
13
17
 
14
18
  Arguments:
@@ -17,33 +21,38 @@ Arguments:
17
21
  Projects:
18
22
  #{project_arguments.to_help}
19
23
  USAGE
20
- end
21
24
  end
22
25
 
23
- def verbose
24
- arguments.map(&:key).include?("-v")
26
+ def run
27
+ project.nil? ? ecosystem_status : project_status
28
+ end
29
+
30
+ def project
31
+ Projects::projects.select { |project| arguments.map(&:key).include?(project.name) }.first
32
+ end
33
+
34
+ def with_git?
35
+ arguments.map(&:key).include?("-g")
36
+ end
37
+
38
+ def project_type
39
+ arguments.map(&:key).include?("--apps") ? 'applications' : (arguments.map(&:key).include?("--gems") ? 'gems' : 'projects')
25
40
  end
26
41
 
27
42
  def ecosystem_status
28
- if Projects::projects.empty?
29
- puts "No projects configured."
43
+ if Projects::send(project_type).empty?
44
+ puts "No #{project_type} in your ecosystem."
30
45
  return
31
46
  end
32
47
 
33
- puts "The following projects are configured in your ecosystem: "
34
- Projects::projects.each do |project|
48
+ Projects::send(project_type).each do |project|
35
49
  puts
36
- Tasks::ProjectStatus.perform(project, verbose)
50
+ Tasks::ProjectStatus.perform(project, with_git?)
37
51
  end
38
52
  end
39
53
 
40
- def project_status(project)
41
- Tasks::ProjectStatus.perform(project, verbose)
42
- end
43
-
44
- def run
45
- project = Projects::projects.select { |project| arguments.map(&:key).include?(project.name) }.first
46
- project.nil? ? ecosystem_status : project_status(project)
54
+ def project_status
55
+ Tasks::ProjectStatus.perform(project, with_git?)
47
56
  end
48
57
  end
49
58
  end
@@ -25,7 +25,7 @@ module Greenhouse
25
25
 
26
26
  if args.length > 0 && args[0].is_a?(Hash)
27
27
  opts = args.slice!(0)
28
- @valid = (opts[:valid].is_a?(Array) ? opts[:valid].map(&:to_s) : opts[:valid].to_s) if opts.has_key?(:valid)
28
+ @valid = (opts[:valid].is_a?(Array) ? opts[:valid].map(&:to_s) : [opts[:valid].to_s]) if opts.has_key?(:valid)
29
29
  @summary = opts[:summary] if opts.has_key?(:summary)
30
30
  end
31
31
 
@@ -12,12 +12,11 @@ module Greenhouse
12
12
 
13
13
  def run
14
14
  @script ||= new
15
- raise "You have not defined a `run` method for your script." unless @script.respond_to?(:run)
15
+ raise "You must define a `run` method for your script." unless @script.respond_to?(:run)
16
16
  @script.run
17
17
  end
18
18
 
19
19
  def validate_arguments(val=nil)
20
- return validate_arguments? if val.nil?
21
20
  @validate_arguments = val
22
21
  end
23
22
 
@@ -49,51 +48,73 @@ module Greenhouse
49
48
  end
50
49
 
51
50
  def project_argument(proj)
52
- @valid_projs ||= Arguments.new
51
+ @valid_projects ||= Arguments.new
53
52
  if proj.is_a?(Argument)
54
- @valid_projs << proj
53
+ @valid_projects << proj
55
54
  elsif proj.is_a?(Hash)
56
- @valid_projs << Argument.new(proj.keys.first.to_s, proj.values.first)
55
+ @valid_projects << Argument.new(proj.keys.first.to_s, proj.values.first)
57
56
  elsif proj.is_a?(Array)
58
- @valid_projs << Argument.new(proj[0].to_s, (proj.length > 1 ? proj[1] : []))
57
+ @valid_projects << Argument.new(proj[0].to_s, (proj.length > 1 ? proj[1] : []))
59
58
  else
60
- @valid_projs << Argument.new(proj.to_s)
59
+ @valid_projects << Argument.new(proj.to_s)
61
60
  end
62
- @valid_projs.last
61
+ @valid_projects.last
63
62
  end
64
63
 
65
64
  def project_arguments(*projs)
66
- @valid_projs ||= Arguments.new
67
- return @valid_projs if projs.empty?
65
+ @valid_projects ||= Arguments.new
66
+ return @valid_projects if projs.empty?
68
67
 
69
68
  projs.each { |proj| project_argument(proj) }
70
- @valid_projs
69
+ @valid_projects
71
70
  end
72
71
 
73
72
  def arguments(*args)
74
- @arguments ||= nil
75
- return @arguments unless @arguments.nil?
73
+ add_arguments(*args)
74
+ end
75
+
76
+ def user_arguments
77
+ arguments
78
+ end
79
+
80
+ def set_arguments(*args)
76
81
  @arguments = Arguments.new
82
+ add_arguments(*args)
83
+ end
84
+
85
+ def add_arguments(*args)
86
+ @arguments ||= Arguments.new
77
87
  args.each_with_index do |arg,a|
78
- argarr = arg.split("=")
79
- argkey = argarr.slice!(0)
88
+ argk, argv = *parse_arg(arg)
80
89
 
81
- if !valid_arguments.clone.concat(project_arguments).map(&:keys).any? { |keys| keys.include?(argkey) } && !arg.match(/\A(-)+[a-z0-9\-]=?.*\Z/i) && (a > 0 && args[a-1].match(/\A(-)+[a-z0-9\-]=?.*\Z/i)) && !@arguments.empty?
90
+ if !argument_flag?(arg) && !valid_argument?(argk) && (a > 0 && argument_flag?(args[a-1]))
82
91
  @arguments.last.value = arg
83
92
  next
84
93
  end
85
94
 
86
- if validate_arguments?
87
- raise InvalidArgument, "Invalid Argument: #{arg}" unless valid_arguments.clone.concat(project_arguments).map(&:keys).any? { |keys| keys.include?(argkey) }
88
- @arguments << valid_arguments.clone.concat(project_arguments).select { |varg| varg.keys.include?(argkey) }.first
89
- else
90
- valid_arg = valid_arguments.clone.concat(project_arguments).select { |varg| varg.keys.include?(argkey) }.first
91
- @arguments << (valid_arg || Argument.new(argkey))
92
- end
93
- @arguments.last.value = argarr.join("=") unless argarr.empty?
95
+ raise InvalidArgument, "Invalid Argument: #{arg}" if validate_arguments? && !valid_argument?(argk)
96
+ @arguments << argument_object(argk)
97
+ @arguments.last.value = argv unless argv.empty?
94
98
  end
95
99
  @arguments
96
100
  end
101
+
102
+ def parse_arg(arg)
103
+ arga = arg.split("=")
104
+ [arga.slice!(0), arga.join("=")]
105
+ end
106
+
107
+ def valid_argument?(key)
108
+ valid_arguments.clone.concat(project_arguments).map(&:keys).flatten.include?(key)
109
+ end
110
+
111
+ def argument_flag?(arg)
112
+ arg.match(/\A(-)+[a-z0-9\-]=?.*\Z/i)
113
+ end
114
+
115
+ def argument_object(key)
116
+ valid_arguments.clone.concat(project_arguments).select { |varg| varg.keys.include?(key) }.first || Argument.new(key)
117
+ end
97
118
  end
98
119
 
99
120
  module InstanceMethods
@@ -14,6 +14,7 @@ require 'greenhouse/tasks/add_project'
14
14
  require 'greenhouse/tasks/push_project'
15
15
  require 'greenhouse/tasks/pull_project'
16
16
  require 'greenhouse/tasks/sync_project'
17
+ require 'greenhouse/tasks/bundle_project'
17
18
  require 'greenhouse/tasks/purge_project'
18
19
  require 'greenhouse/tasks/remove_project'
19
20
  require 'greenhouse/tasks/generate_procfile'
@@ -0,0 +1,13 @@
1
+ module Greenhouse
2
+ module Tasks
3
+ class BundleProject
4
+ include Task
5
+ include ProjectTask
6
+
7
+ def perform(project, cmd='install')
8
+ @project = project
9
+ bundle(cmd)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -7,7 +7,7 @@ module Greenhouse
7
7
  def perform(project, verbose=false)
8
8
  @project = project
9
9
 
10
- @project.repository.fetch if @project.exists?
10
+ @project.repository.fetch if verbose && @project.exists?
11
11
 
12
12
  puts " \e[36m#{@project.title}\e[0m (#{@project.type.capitalize})"
13
13
  puts " #{@project.repository.remote}"
@@ -14,9 +14,9 @@ module Greenhouse
14
14
  base.send :alias_method, :klone, :clone
15
15
  end
16
16
 
17
- def bundle
17
+ def bundle(cmd='install')
18
18
  puts "Running Bundler for \e[36m#{@project.title}\e[0m..."
19
- @project.bundle
19
+ @project.bundle(cmd)
20
20
  true
21
21
  rescue Exception => e
22
22
  puts "\e[31mError running Bundler for #{@project.title}\e[0m"
@@ -9,6 +9,10 @@ module Greenhouse
9
9
  end
10
10
 
11
11
  module ClassMethods
12
+ def self.extended(base)
13
+ base.send :attr_reader, :results
14
+ end
15
+
12
16
  def perform(*args)
13
17
  @task = new
14
18
  @task.before(*args) if @task.respond_to?(:before)
@@ -16,6 +20,10 @@ module Greenhouse
16
20
  @task.after(*args) if @task.respond_to?(:after)
17
21
  @task
18
22
  end
23
+
24
+ def results
25
+ (@task ||= new).results
26
+ end
19
27
  end
20
28
 
21
29
  module InstanceMethods
@@ -1,8 +1,14 @@
1
1
  module Greenhouse
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
4
4
 
5
5
  __END__
6
+ 0.0.7:
7
+ * Simple bundler command to run install/update for a single or all projects
8
+ * Refactor `status` command, renamed --verbose flag to --git, only fetching git remotes with --git flag
9
+ * Cleanup for script arguments
10
+ * Dummy `specs` command as a placeholder to be overridden by extensions
11
+
6
12
  0.0.6:
7
13
  * Don't downcase git repos (duh)
8
14
  * Add console command to easily run rails console for rails apps
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: greenhouse
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Rebec
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-31 00:00:00.000000000 Z
11
+ date: 2013-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -73,7 +73,7 @@ dependencies:
73
73
  - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
- type: :development
76
+ type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
@@ -107,6 +107,7 @@ files:
107
107
  - lib/greenhouse/tasks/sync_project.rb
108
108
  - lib/greenhouse/tasks/project_status.rb
109
109
  - lib/greenhouse/tasks/pull_project.rb
110
+ - lib/greenhouse/tasks/bundle_project.rb
110
111
  - lib/greenhouse/tasks/task.rb
111
112
  - lib/greenhouse/tasks/push_project.rb
112
113
  - lib/greenhouse/tasks/remove_project.rb
@@ -128,10 +129,12 @@ files:
128
129
  - lib/greenhouse/commands/configure.rb
129
130
  - lib/greenhouse/commands/help.rb
130
131
  - lib/greenhouse/commands/init.rb
132
+ - lib/greenhouse/commands/specs.rb
131
133
  - lib/greenhouse/commands/purge.rb
132
134
  - lib/greenhouse/commands/remove.rb
133
135
  - lib/greenhouse/commands/new.rb
134
136
  - lib/greenhouse/commands/status.rb
137
+ - lib/greenhouse/commands/bundle.rb
135
138
  - lib/greenhouse/commands/sync.rb
136
139
  - lib/greenhouse/commands/console.rb
137
140
  - lib/greenhouse/commands/launch.rb
@@ -164,3 +167,4 @@ signing_key:
164
167
  specification_version: 4
165
168
  summary: Suite of tools for working on an entire 'ecosystem' of ruby gems and applications.
166
169
  test_files: []
170
+ has_rdoc: