lib/kameleon/cli.rb in kameleon-builder-2.4.0 vs lib/kameleon/cli.rb in kameleon-builder-2.5.0

- old
+ new

@@ -60,12 +60,11 @@ rescue raise TemplateNotFound, "Template '#{template_name}' not found. " \ "To see all templates, run the command "\ "`kameleon template ls`" else - files2copy = tpl.base_recipes_files + tpl.files + tpl.data - files2copy.each do |path| + tpl.all_files.each do |path| relative_path = path.relative_path_from(Kameleon.env.repositories_path) dst = File.join(Kameleon.env.workspace, relative_path) copy_file(path, dst) end end @@ -98,12 +97,14 @@ # register CLI::Recipe, 'recipe', 'recipe', 'Manages the local recipes' register CLI::Template, 'template', 'template', 'Lists and imports templates' class_option :color, :type => :boolean, :default => Kameleon.default_values[:color], :desc => "Enables colorization in output" + class_option :verbose, :type => :boolean, :default => Kameleon.default_values[:verbose], + :desc => "Enables verbose output for kameleon users" class_option :debug, :type => :boolean, :default => Kameleon.default_values[:debug], - :desc => "Enables debug output" + :desc => "Enables debug output for kameleon developpers" class_option :script, :type => :boolean, :default => Kameleon.default_values[:script], :desc => "Never prompts for user intervention", :aliases => "-s" map %w(-h --help) => :help @@ -148,12 +149,11 @@ rescue raise TemplateNotFound, "Template '#{template_name}' not found. " \ "To see all templates, run the command "\ "`kameleon templates`" else - files2copy = tpl.base_recipes_files + tpl.files + tpl.data - files2copy.each do |path| + tpl.all_files.each do |path| relative_path = path.relative_path_from(Kameleon.env.repositories_path) dst = File.join(Kameleon.env.workspace, relative_path) copy_file(path, dst) end Dir::mktmpdir do |tmp_dir| @@ -168,15 +168,29 @@ copy_file(recipe_temp, recipe_path) end end end - desc "info [RECIPE_PATH]", "Display detailed information about a recipe" + desc "info [[RECIPE_PATH]]", "Display detailed information about a recipe" method_option :global, :type => :hash , :default => {}, :aliases => "-g", :desc => "Set custom global variables." - def info(recipe_path) + method_option :from_cache, :type => :string , + :default => nil, + :desc => "Get info from a persistent cache tar file (ignore recipe path)" + + def info(recipe_path=nil) + if recipe_path.nil? && !options[:from_cache].nil? + unless File.file?(options[:from_cache]) + raise CacheError, "The specified cache file "\ + "\"#{options[:from_cache]}\" do not exists" + end + Kameleon.ui.info("Using the cached recipe") + @cache = Kameleon::Persistent_cache.instance + @cache.cache_path = options[:from_cache] + recipe_path = @cache.get_recipe + end recipe = Kameleon::Recipe.new(recipe_path) recipe.resolve! recipe.display_info end @@ -209,10 +223,14 @@ method_option :global, :type => :hash, :default => {}, :aliases => "-g", :desc => "Set custom global variables." def build(recipe_path=nil) if recipe_path.nil? && !options[:from_cache].nil? + unless File.file?(options[:from_cache]) + raise CacheError, "The specified cache file "\ + "\"#{options[:from_cache]}\" do not exists" + end Kameleon.ui.info("Using the cached recipe") @cache = Kameleon::Persistent_cache.instance @cache.cache_path = options[:from_cache] recipe_path = @cache.get_recipe end @@ -268,10 +286,17 @@ Kameleon.env = Kameleon::Environment.new(self.options) if !$stdout.tty? or !options["color"] Thor::Base.shell = Thor::Shell::Basic end Kameleon.ui = Kameleon::UI::Shell.new(self.options) - Kameleon.ui.level = "debug" if self.options["debug"] + + if (self.options["debug"] or ENV['KAMELEON_DEBUG']) + Kameleon.ui.level = "debug" + elsif self.options["verbose"] + Kameleon.ui.level = "verbose" + end + Kameleon.ui.verbose("The level of output is set to #{Kameleon.ui.level}") + opts = args[1] cmd_name = args[2][:current_command].name if opts.include? "--help" or opts.include? "-h" Main.command_help(Kameleon.ui.shell, cmd_name) raise Kameleon::Exit