lib/klipp.rb in klipp-0.2.1 vs lib/klipp.rb in klipp-0.2.2
- old
+ new
@@ -14,10 +14,14 @@
module Klipp
class Hint < StandardError
end
+ class ClusterError < StandardError
+ attr_accessor :messages
+ end
+
def self.env
@@env ||= StringInquirer.new('prod')
end
def self.env=(env)
@@ -45,13 +49,15 @@
0 # exit code
rescue Exception => e
case e
when Klipp::Hint
Formatador.display_line("[yellow][?] #{e.message}[/]")
+ when Klipp::ClusterError
+ e.messages.each { |msg| Formatador.display_line("[red][!] #{msg}[/]\n") }
else
- Formatador.display_line("[red][!] #{e.message}[/]")
- Formatador.display_line(e.backtrace[0..10].join("\n"))
+ Formatador.display_line("[red][!] #{e.message}[/]\n")
+ Formatador.display_line(e.backtrace.first)
end
1 # exit code
end
def self.cli_prepare(params=[])
@@ -88,12 +94,31 @@
else
creator = Klipp::Creator.from_file File.join(Dir.pwd, 'Klippfile')
end
spec_path = Template::Spec.spec_path_for_identifier creator.identifier
spec = Template::Spec.from_file spec_path
- spec.set_token_values(creator.tokens, params.splice_option('-v'))
+ validation_errors = Array.new
+
+ begin
+ spec.set_token_values(creator.tokens, params.splice_option('-v'))
+ rescue Exception => e
+ validation_errors << e.message
+ end
+
+ begin
+ spec.confirm_required_files
+ rescue Exception => e
+ validation_errors << e.message
+ end
+
+ if validation_errors.length > 0
+ e = Klipp::ClusterError.new
+ e.messages = validation_errors
+ raise e
+ end
+
block_actions = spec.block_actions_under_git && git_repository?
if spec.pre_actions.count > 0
if block_actions
Formatador.display_line("[yellow][i][/] Git repository found, not running pre-actions (see .klippspec).")
puts()
@@ -158,10 +183,10 @@
end
end
class StringInquirer < String
def method_missing(method_name, *arguments)
- if method_name.to_s[-1,1] == '?'
+ if method_name.to_s[-1, 1] == '?'
self == method_name.to_s[0..-2]
else
super
end
end
\ No newline at end of file