chekku 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -45,7 +45,7 @@ module Chekku
45
45
  # @raise [AppNameNotStringError] if Definition is not correct and executable isn't a string
46
46
  # @raise [AppNameNotSaneError] if Definition executable isn't safe (spaces, special chars and so on)
47
47
  def chekku!(version = nil, args = {})
48
- raise(DefinitionValidationError, "not installed") unless exists?
48
+ raise(NotInstalledError, "not installed") unless exists?
49
49
  validates version, args
50
50
  end
51
51
 
@@ -1,6 +1,7 @@
1
1
  #encoding: utf-8
2
2
  require_relative 'definition'
3
3
  require_relative 'definitions_service'
4
+ require_relative 'installer'
4
5
 
5
6
  class Chekku::Definitions
6
7
 
@@ -17,6 +18,7 @@ class Chekku::Definitions
17
18
  def initialize
18
19
  @definitions_service = Chekku::DefinitionsService.new
19
20
  @definitions_service.load_definitions_for @chekkufile
21
+ @installer ||= Chekku::Installer.new
20
22
  end
21
23
 
22
24
  # Parse the file and evaluate every dependency
@@ -47,6 +49,9 @@ class Chekku::Definitions
47
49
  puts "[\033[31m✗\033[0m] #{name}: #{e.message}\n"
48
50
  rescue ChekkuError => e
49
51
  puts "\033[31mERROR: #{e.message}\033[0m\n"
52
+ rescue NotInstalledError => e
53
+ puts "[\033[31m✗\033[0m] #{name}: #{e.message}\n"
54
+ @installer.install_app? name
50
55
  end
51
56
 
52
57
  # Retrieve the Definition instance from the DefinitionService
@@ -4,3 +4,4 @@ class AppNameNotSaneError < ChekkuError; end
4
4
  class AppNameNotStringError < ChekkuError; end
5
5
  class DefinitionNotFoundError < ChekkuError; end
6
6
  class DefinitionValidationError < DefinitionsError; end
7
+ class NotInstalledError < StandardError; end
@@ -43,10 +43,10 @@ class Chekku::Fetcher
43
43
 
44
44
  def ensure_definitions_are_up_to_date(definitions_yaml)
45
45
  last_updated = definitions_yaml.delete('updated_at')
46
- definitions_yaml.tap do |definitions_yaml|
47
- if too_long_ago?(last_updated)
48
- defintions_yaml = fetch_new_distant_definitions
49
- end
46
+ if too_long_ago?(last_updated)
47
+ fetch_new_distant_definitions
48
+ else
49
+ definitions_yaml
50
50
  end
51
51
  end
52
52
 
@@ -0,0 +1,35 @@
1
+ #encoding: utf-8
2
+ class Chekku::Installer
3
+
4
+ def install_app?(app_name)
5
+ return if @never_install
6
+ install_answer = ask_user(app_name) unless @install_all
7
+ @never_install = true if install_answer == 'none'
8
+ @install_all = true if install_answer == 'all' || install_answer == 'a'
9
+ if @install_all || install_answer == 'yes' || install_answer == 'y'
10
+ puts "Starting #{app_name} installation"
11
+ install_app app_name
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def ask_user(app_name)
18
+ print "Would you like to install #{app_name}? (y)es/(n)o/(a)ll/none : "
19
+ gets.downcase.chomp
20
+ end
21
+
22
+ def install_app(app_name)
23
+ if RbConfig::CONFIG['host_os'].include? 'darwin'
24
+ system "brew install #{app_name}"
25
+ if $?.exitstatus == 0
26
+ "Installation of #{app_name} done"
27
+ else
28
+ "Installation of #{app_name} failed"
29
+ end
30
+ else
31
+ puts "[\033[31m✗\033[0m] We Only support OSX for installation for the moment\n"
32
+ end
33
+ end
34
+
35
+ end
@@ -1,3 +1,3 @@
1
1
  module Chekku
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end
@@ -85,7 +85,7 @@ describe Chekku::Definition do
85
85
 
86
86
  it 'should says x if soft does not exist' do
87
87
  definition.stub(:exists?).and_return(false)
88
- expect { definition.chekku! }.to raise_error(DefinitionValidationError)
88
+ expect { definition.chekku! }.to raise_error(NotInstalledError)
89
89
  end
90
90
  end
91
91
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: chekku
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.0
5
+ version: 0.6.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Yannick Schutz
@@ -101,6 +101,7 @@ files:
101
101
  - lib/chekku/definitions_service.rb
102
102
  - lib/chekku/errors.rb
103
103
  - lib/chekku/fetcher.rb
104
+ - lib/chekku/installer.rb
104
105
  - lib/chekku/version.rb
105
106
  - spec/lib/definition_spec.rb
106
107
  - spec/lib/definitions_service_spec.rb