hobo-inviqa 0.0.7.pre.rc3 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. data/Gemfile.lock +4 -19
  2. data/Guardfile +2 -2
  3. data/Hobofile +1 -5
  4. data/bin/hobo +18 -12
  5. data/hobo.gemspec +0 -3
  6. data/lib/hobo.rb +1 -8
  7. data/lib/hobo/cli.rb +3 -14
  8. data/lib/hobo/error_handlers/debug.rb +2 -5
  9. data/lib/hobo/error_handlers/friendly.rb +8 -8
  10. data/lib/hobo/errors.rb +1 -11
  11. data/lib/hobo/helper/shell.rb +2 -3
  12. data/lib/hobo/helper/vm_command.rb +14 -164
  13. data/lib/hobo/lib/host_check.rb +6 -20
  14. data/lib/hobo/lib/host_check/deps.rb +4 -22
  15. data/lib/hobo/lib/host_check/git.rb +17 -41
  16. data/lib/hobo/lib/host_check/ruby.rb +20 -30
  17. data/lib/hobo/lib/host_check/vagrant.rb +6 -37
  18. data/lib/hobo/lib/s3sync.rb +44 -22
  19. data/lib/hobo/lib/seed/project.rb +4 -8
  20. data/lib/hobo/patches/slop.rb +2 -21
  21. data/lib/hobo/tasks/assets.rb +15 -12
  22. data/lib/hobo/tasks/deps.rb +6 -40
  23. data/lib/hobo/tasks/host.rb +19 -0
  24. data/lib/hobo/tasks/tools.rb +6 -10
  25. data/lib/hobo/tasks/vm.rb +11 -64
  26. data/lib/hobo/ui.rb +10 -27
  27. data/lib/hobo/util.rb +2 -36
  28. data/lib/hobo/version.rb +2 -2
  29. data/spec/hobo/asset_applicator_spec.rb +2 -2
  30. data/spec/hobo/cli_spec.rb +24 -35
  31. data/spec/hobo/config/file_spec.rb +3 -1
  32. data/spec/hobo/error_handlers/debug_spec.rb +5 -39
  33. data/spec/hobo/error_handlers/friendly_spec.rb +21 -38
  34. data/spec/hobo/help_formatter_spec.rb +3 -3
  35. data/spec/hobo/helpers/file_locator_spec.rb +2 -2
  36. data/spec/hobo/helpers/shell_spec.rb +2 -2
  37. data/spec/hobo/helpers/vm_command_spec.rb +24 -36
  38. data/spec/hobo/lib/s3sync_spec.rb +3 -6
  39. data/spec/hobo/lib/seed/project_spec.rb +3 -2
  40. data/spec/hobo/lib/seed/replacer_spec.rb +2 -1
  41. data/spec/hobo/lib/seed/seed_spec.rb +3 -2
  42. data/spec/hobo/logging_spec.rb +2 -2
  43. data/spec/hobo/metadata_spec.rb +2 -2
  44. data/spec/hobo/null_spec.rb +2 -2
  45. data/spec/hobo/paths_spec.rb +2 -1
  46. data/spec/hobo/ui_spec.rb +20 -104
  47. data/spec/spec_helper.rb +0 -1
  48. metadata +48 -57
  49. checksums.yaml +0 -15
  50. data/.editorconfig +0 -10
  51. data/lib/hobo/error_handlers/exit_code_map.rb +0 -16
  52. data/lib/hobo/helper/http_download.rb +0 -41
  53. data/lib/hobo/tasks/config.rb +0 -15
  54. data/lib/hobo/tasks/system.rb +0 -15
  55. data/lib/hobo/tasks/system/completions.rb +0 -76
  56. data/spec/hobo/util_spec.rb +0 -75
@@ -1,7 +1,7 @@
1
1
  require 'slop'
2
2
 
3
3
  class Slop
4
- attr_accessor :long_desc, :arg_list, :hidden, :desc, :unparsed
4
+ attr_accessor :long_desc, :arg_list, :hidden, :desc
5
5
 
6
6
  # Slop has a description method but it uses @config which is inherited
7
7
  # This is not desired behaviour
@@ -29,23 +29,4 @@ class Slop
29
29
  @config[:project_only] = value unless value.nil?
30
30
  @config[:project_only]
31
31
  end
32
-
33
- alias :old_parse! :parse!
34
- def parse!(items = ARGV, &block)
35
- if @unparsed.nil?
36
- split_index = items.index('--')
37
-
38
- unparsed = []
39
- unless split_index.nil?
40
- unparsed = items.slice(split_index + 1, items.length)
41
- items = items.slice(0, split_index)
42
- end
43
-
44
- @unparsed = unparsed.map do |c|
45
- "\'#{c.gsub("'", '\\\'').gsub('(', '\\(').gsub(')', '\\)')}\'"
46
- end.join(' ')
47
- end
48
-
49
- old_parse!(items, &block)
50
- end
51
- end
32
+ end
@@ -10,8 +10,7 @@ namespace :assets do
10
10
  rescue AWS::S3::Errors::NoSuchBucket
11
11
  Hobo.ui.error " Asset bucket #{Hobo.project_config.asset_bucket} does not exist!"
12
12
  rescue AWS::Errors::MissingCredentialsError
13
- Hobo.ui.warning " AWS credentials not set!"
14
- Hobo.ui.warning " Either set the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY env vars or run `hobo config` to set them."
13
+ Hobo.ui.error " AWS credentials not set!\n\nRun `hobo host config` to set them."
15
14
  end
16
15
  end
17
16
 
@@ -25,8 +24,8 @@ namespace :assets do
25
24
  s3_uri = "s3://#{Hobo.project_config.asset_bucket}/#{env}/"
26
25
 
27
26
  sync = Hobo::Lib::S3Sync.new(
28
- maybe(Hobo.user_config.aws.access_key_id) || ENV['AWS_ACCESS_KEY_ID'],
29
- maybe(Hobo.user_config.aws.secret_access_key) || ENV['AWS_SECRET_ACCESS_KEY']
27
+ maybe(Hobo.user_config.aws.access_key_id),
28
+ maybe(Hobo.user_config.aws.secret_access_key)
30
29
  )
31
30
 
32
31
  handle_s3_error do
@@ -50,8 +49,8 @@ namespace :assets do
50
49
  s3_uri = "s3://#{Hobo.project_config.asset_bucket}/#{env}/"
51
50
 
52
51
  sync = Hobo::Lib::S3Sync.new(
53
- maybe(Hobo.user_config.aws.access_key_id) || ENV['AWS_ACCESS_KEY_ID'],
54
- maybe(Hobo.user_config.aws.secret_access_key) || ENV['AWS_SECRET_ACCESS_KEY']
52
+ maybe(Hobo.user_config.aws.access_key_id),
53
+ maybe(Hobo.user_config.aws.secret_access_key)
55
54
  )
56
55
 
57
56
  handle_s3_error do
@@ -88,7 +87,9 @@ end
88
87
  # Built in applicators
89
88
  Hobo.asset_applicators.register /.*\.files\.(tgz|tar\.gz|tar\.bz2)/ do |file|
90
89
  Hobo.ui.title "Applying file dump (#{file})"
91
- vm_shell "tar -xvf #{file.shellescape}"
90
+ Dir.chdir Hobo.project_path do
91
+ shell "tar -xvf #{file.shellescape}"
92
+ end
92
93
  end
93
94
 
94
95
  Hobo.asset_applicators.register /.*\.sql\.gz/ do |file|
@@ -96,13 +97,15 @@ Hobo.asset_applicators.register /.*\.sql\.gz/ do |file|
96
97
  db = File.basename(matches[1])
97
98
 
98
99
  begin
99
- shell(vm_mysql(:mysql => 'mysqladmin', :append => " create #{db.shellescape}"))
100
- rescue Hobo::ExternalCommandError => e
100
+ shell(vm_mysql << "USE #{db}")
101
101
  Hobo.ui.warning "Already applied (#{file})"
102
- raise e if e.exit_code != 1
103
102
  next
103
+ rescue Hobo::ExternalCommandError => e
104
+ raise e if e.exit_code != 1
104
105
  end
105
106
 
106
107
  Hobo.ui.title "Applying mysqldump (#{file})"
107
- shell(vm_mysql(:auto_echo => false, :db => db) < "zcat #{file.shellescape}")
108
- end
108
+
109
+ shell(vm_mysql << "CREATE DATABASE #{db}")
110
+ shell(vm_mysql(:auto_echo => false, :db => db) << "zcat #{file.shellescape}")
111
+ end
@@ -21,30 +21,10 @@ namespace :deps do
21
21
  Rake::Task["tools:composer"].invoke
22
22
  Hobo.ui.title "Installing composer dependencies"
23
23
  Dir.chdir Hobo.project_path do
24
- ansi = Hobo.ui.supports_color? ? '--ansi' : ''
25
- args = [ "php bin/composer.phar install #{ansi} --prefer-dist", { realtime: true, indent: 2 } ]
26
- complete = false
27
-
28
- check = Hobo::Lib::HostCheck.check(:filter => /php_present/)
29
-
30
- if check["Php present"] == :ok
31
- begin
32
- shell *args
33
- complete = true
34
- rescue Hobo::ExternalCommandError
35
- Hobo.ui.warning "Installing composer dependencies locally failed!"
36
- end
37
- end
38
-
39
- if !complete
40
- vm_shell *args
41
- end
42
-
43
- Hobo.ui.success "Composer dependencies installed"
24
+ shell "php", File.join(Hobo.project_bin_path, 'composer.phar'), "install", "--ansi", realtime: true, indent: 2
44
25
  end
45
-
46
- Hobo.ui.separator
47
26
  end
27
+ Hobo.ui.separator
48
28
  end
49
29
 
50
30
  desc "Install vagrant plugins"
@@ -52,15 +32,10 @@ namespace :deps do
52
32
  plugins = shell "vagrant plugin list", :capture => true
53
33
  locate "*Vagrantfile" do
54
34
  File.read("Vagrantfile").split("\n").each do |line|
55
- next if line.match /^\s*#/
56
35
  next unless line.match /Vagrant\.require_plugin (.*)/
57
36
  plugin = $1.gsub(/['"]*/, '')
58
37
  next if plugins.include? "#{plugin} "
59
-
60
38
  Hobo.ui.title "Installing vagrant plugin: #{plugin}"
61
- if plugin == 'vagrant-berkshelf'
62
- # Hack to install minitar
63
- end
64
39
  bundle_shell "vagrant", "plugin", "install", plugin, :realtime => true, :indent => 2
65
40
  Hobo.ui.separator
66
41
  end
@@ -70,22 +45,13 @@ namespace :deps do
70
45
  desc "Install chef dependencies"
71
46
  task :chef => [ "deps:gems" ] do
72
47
  locate "*Cheffile" do
73
- Hobo.ui.title "Installing chef dependencies via librarian"
48
+ Hobo.ui.title "Installing chef dependencies"
74
49
  Bundler.with_clean_env do
75
- bundle_shell "librarian-chef", "install", "--verbose", :realtime => true, :indent => 2 do |line|
76
- line =~ /Installing.*</ ? line.strip + "\n" : nil
50
+ bundle_shell "librarian-chef", "install", "--verbose", realtime: true, indent: 2 do |line|
51
+ line =~ /Installing.*</ ? line : nil
77
52
  end
78
53
  end
79
54
  Hobo.ui.separator
80
55
  end
81
-
82
- locate "*Berksfile" do
83
- Hobo.ui.title "Installing chef dependencies via berkshelf"
84
- Bundler.with_clean_env do
85
- bundle_shell "berks", "install", :realtime => true, :indent => 2
86
- bundle_shell "berks", "install", "--path", "cookbooks"
87
- end
88
- Hobo.ui.separator
89
- end
90
56
  end
91
- end
57
+ end
@@ -0,0 +1,19 @@
1
+ namespace :host do
2
+ task :config do
3
+ config = Hobo.user_config
4
+
5
+ config.full_name = Hobo.ui.ask "Full name", :default => config.full_name
6
+ config.email = Hobo.ui.ask "Email", :default => config.email
7
+
8
+ config.aws = {}
9
+ config.aws.access_key_id = Hobo.ui.ask "AWS access key ID", :default => config.aws.access_key_id
10
+ config.aws.secret_access_key = Hobo.ui.ask "AWS secret access key", :default => config.aws.secret_access_key
11
+
12
+ Hobo::Config::File.save(Hobo.user_config_file, config)
13
+ File.chmod(0600, Hobo.user_config_file)
14
+ end
15
+
16
+ task :check do
17
+ Hobo::HostCheck.check false
18
+ end
19
+ end
@@ -1,17 +1,13 @@
1
- desc "Tasks to retrieve common tools"
2
- hidden
3
1
  namespace :tools do
4
-
5
- desc "Fetch composer"
6
2
  task :composer do
7
3
  bin_file = File.join(Hobo.project_bin_path, "composer.phar")
8
4
  unless File.exists?(bin_file)
9
- Hobo.ui.success "Getting composer"
5
+ Hobo.ui.success "Getting composer.phar"
10
6
  FileUtils.mkdir_p File.dirname(bin_file)
11
- vm_shell "cd bin && php -r \"readfile('https://getcomposer.org/installer');\" | php", :realtime => true, :indent => 2
12
- else
13
- Hobo.ui.success "Composer already available in bin/composer.phar"
7
+ Dir.chdir File.dirname(bin_file) do
8
+ shell "php", "-r", "eval('?>'.file_get_contents('https://getcomposer.org/installer'));", realtime: true, indent: 2
9
+ end
10
+ Hobo.ui.separator
14
11
  end
15
- Hobo.ui.separator
16
12
  end
17
- end
13
+ end
data/lib/hobo/tasks/vm.rb CHANGED
@@ -7,43 +7,14 @@ namespace :vm do
7
7
  end
8
8
  end
9
9
 
10
- def vagrant_exec *args
11
- opts = { :realtime => true, :indent => 2 }
12
- color = Hobo.ui.supports_color? ? '--color' : '--no-color'
13
-
14
- if OS.windows?
15
- opts[:env] = { 'VAGRANT_HOME' => windows_short(dir) } if ENV['HOME'].match(/\s+/) && !ENV['VAGRANT_HOME']
16
- end
17
-
18
- args.unshift 'vagrant'
19
- args.push color
20
- args.push opts
21
-
22
- bundle_shell *args
23
- end
24
-
25
- def windows_short dir
26
- segments = dir.gsub(/\\/, '/').split('/')
27
- segments.map do |segment|
28
- if segment.match /\s+/
29
- # This may fail in some edge cases but better than naught
30
- # See the following link for the correct solution
31
- # http://stackoverflow.com/questions/10224572/convert-long-filename-to-short-filename-8-3
32
- segment.upcase.gsub(/\s+/, '')[0...6] + '~1'
33
- else
34
- segment
35
- end
36
- end.join('/')
37
- end
38
-
39
10
  desc "Start & provision VM"
40
- task :up => [ 'deps:chef', 'assets:download', 'vm:start', 'vm:provision', 'deps:composer', 'assets:apply' ]
11
+ task :up => [ 'deps:chef', 'deps:composer', 'assets:download', 'vm:start', 'vm:provision', 'assets:apply' ]
41
12
 
42
13
  desc "Stop VM"
43
14
  task :stop => [ "deps:gems" ] do
44
15
  vagrantfile do
45
16
  Hobo.ui.title "Stopping VM"
46
- vagrant_exec 'suspend'
17
+ bundle_shell "vagrant", "suspend", "--color", realtime: true, indent: 2
47
18
  Hobo.ui.separator
48
19
  end
49
20
  end
@@ -55,7 +26,7 @@ namespace :vm do
55
26
  task :destroy => [ "deps:gems" ] do
56
27
  vagrantfile do
57
28
  Hobo.ui.title "Destroying VM"
58
- vagrant_exec 'destroy', '--force'
29
+ bundle_shell "vagrant", "destroy", "--force", "--color", realtime: true, indent: 2
59
30
  Hobo.ui.separator
60
31
  end
61
32
  end
@@ -64,7 +35,7 @@ namespace :vm do
64
35
  task :start => [ "deps:gems", "deps:vagrant_plugins" ] do
65
36
  vagrantfile do
66
37
  Hobo.ui.title "Starting vagrant VM"
67
- vagrant_exec 'up', '--no-provision'
38
+ bundle_shell "vagrant", "up", "--no-provision", "--color", realtime: true, indent: 2
68
39
  Hobo.ui.separator
69
40
  end
70
41
  end
@@ -73,47 +44,23 @@ namespace :vm do
73
44
  task :provision => [ "deps:gems" ] do
74
45
  vagrantfile do
75
46
  Hobo.ui.title "Provisioning VM"
76
- vagrant_exec 'provision'
47
+ bundle_shell "vagrant", "provision", "--color", realtime: true, indent: 2
77
48
  Hobo.ui.separator
78
49
  end
79
50
  end
80
51
 
81
52
  desc "Open an SSH connection"
82
- task :ssh do |task|
83
- execute = task.opts[:_unparsed]
84
- opts = { :psuedo_tty => STDIN.tty? }
85
-
86
- Hobo.ui.success "Determining VM connection details..." if STDOUT.tty?
87
- command = execute.empty? ? vm_command(nil, opts) : vm_command(execute, opts)
88
- Hobo.logger.debug "vm:ssh: #{command}"
89
-
90
- Hobo.ui.success "Connecting..." if STDOUT.tty?
91
- exec command
53
+ task :ssh do
54
+ exec vm_command
92
55
  end
93
56
 
94
57
  desc "Open a MySQL cli connection"
95
- option '-D=', '--db=', 'Database'
96
- task :mysql do |task|
97
- opts = { :psuedo_tty => STDIN.tty? }
98
- opts[:db] = task.opts[:db] if task.opts[:db]
99
-
100
- Hobo.ui.success "Determining VM connection details..." if STDOUT.tty?
101
- command = vm_mysql(opts)
102
- Hobo.logger.debug "vm:mysql: #{command}"
103
-
104
- Hobo.ui.success "Connecting..." if STDOUT.tty?
105
- exec command
58
+ task :mysql do
59
+ exec vm_mysql
106
60
  end
107
61
 
108
62
  desc "Open a Redis cli connection"
109
63
  task :redis do
110
- opts = { :psuedo_tty => STDIN.tty? }
111
-
112
- Hobo.ui.success "Determining VM connection details..." if STDOUT.tty?
113
- command = vm_command("redis-cli", opts)
114
- Hobo.logger.debug "vm:redis: #{command}"
115
-
116
- Hobo.ui.success "Connecting..." if STDOUT.tty?
117
- exec command
64
+ exec vm_command "redis-cli"
118
65
  end
119
- end
66
+ end
data/lib/hobo/ui.rb CHANGED
@@ -6,8 +6,6 @@ module Hobo
6
6
  end
7
7
 
8
8
  class Ui
9
- include Hobo::Logging
10
-
11
9
  attr_accessor :interactive
12
10
 
13
11
  COLORS = {
@@ -24,12 +22,10 @@ module Hobo
24
22
  :description => [:bold]
25
23
  }
26
24
 
27
- def initialize input = $stdin, output = $stdout, error = $stderr
25
+ def initialize out = $stdout, error = $stderr
28
26
  HighLine.color_scheme = HighLine::ColorScheme.new COLORS
29
- @output_io = output
30
- @out = ::HighLine.new input, output
31
- @error = ::HighLine.new input, error
32
- use_color supports_color?
27
+ @out = ::HighLine.new $stdin, out
28
+ @error = ::HighLine.new $stdin, error
33
29
  end
34
30
 
35
31
  def color_scheme scheme = nil
@@ -37,25 +33,15 @@ module Hobo
37
33
  HighLine.color_scheme
38
34
  end
39
35
 
40
- def supports_color?
41
- return @output_io.tty? unless OS.windows?
42
- return (ENV['ANSICON'] || ENV['TERM'] == 'xterm') && @output_io.tty? # ANSICON or MinTTY && output is TTY
43
- end
44
-
45
36
  def use_color opt = nil
46
37
  HighLine.use_color = opt unless opt.nil?
47
38
  HighLine.use_color?
48
39
  end
49
40
 
50
41
  def ask question, opts = {}
51
- opts = {
52
- :validate => nil,
53
- :default => nil
54
- }.merge(opts)
55
-
56
- unless @interactive
57
- raise Hobo::NonInteractiveError.new(question) if opts[:default].nil?
58
- return opts[:default].to_s
42
+ unless Hobo.ui.interactive
43
+ raise Hobo::NonInteractive.new(question) if opts[:default].nil?
44
+ return opts[:default]
59
45
  end
60
46
 
61
47
  question = "#{question} [#{opts[:default]}]" if opts[:default]
@@ -65,8 +51,7 @@ module Hobo
65
51
  q.validate = opts[:validate] if opts[:validate]
66
52
  q.readline
67
53
  end
68
- answer = answer.to_s
69
- answer.strip.empty? ? opts[:default].to_s : answer.strip
54
+ answer.strip.empty? ? opts[:default] : answer.strip
70
55
  rescue EOFError
71
56
  Hobo.ui.info ""
72
57
  ""
@@ -80,7 +65,7 @@ module Hobo
80
65
  end
81
66
 
82
67
  def separator
83
- info(supports_color? ? "" : "\n")
68
+ info ""
84
69
  end
85
70
 
86
71
  def color *args
@@ -115,9 +100,7 @@ module Hobo
115
100
 
116
101
  def say channel, message, color
117
102
  return if message.nil?
118
- message = color ? channel.color(message, color) : message
119
- channel.say(message) unless logger.level <= Logger::DEBUG
120
- logger.debug(message)
103
+ channel.say(color ? channel.color(message, color) : message)
121
104
  end
122
105
  end
123
- end
106
+ end
data/lib/hobo/util.rb CHANGED
@@ -1,41 +1,7 @@
1
- require 'ruby-progressbar'
2
-
3
1
  module Hobo
4
2
  class << self
5
-
6
- attr_accessor :project_bar_cache
7
-
8
3
  def in_project?
9
- !!Hobo.project_path
10
- end
11
-
12
- def progress file, increment, total, type, opts = {}
13
- opts = {
14
- :title => File.basename(file),
15
- :total => total,
16
- :format => "%t [%B] %p%% %e"
17
- }.merge(opts)
18
-
19
- # Hack to stop newline spam on windows
20
- opts[:length] = 79 if Gem::win_platform?
21
-
22
- @progress_bar_cache ||= {}
23
-
24
- if type == :reset
25
- type = :update
26
- @progress_bar_cache.delete file
27
- end
28
-
29
- @progress_bar_cache[file] ||= ProgressBar.create(opts)
30
-
31
- case type
32
- when :update
33
- @progress_bar_cache[file].progress += increment
34
- when :finished
35
- @progress_bar_cache[file].finish
36
- end
37
-
38
- return @progress_bar_cache[file]
4
+ !Hobo.project_path.nil?
39
5
  end
40
6
  end
41
- end
7
+ end