class Kameleon::Main
Public Class Methods
Source
# File lib/kameleon/cli.rb, line 482 def initialize(*args) super self.options ||= {} 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) 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}") end
Calls superclass method
Source
# File lib/kameleon/cli.rb, line 170 def self.source_root Kameleon.env.repositories_path end
Source
# File lib/kameleon/cli.rb, line 499 def self.start(*args) # `kameleon build -h` does not work without the following, except for subcommands... # Ref: https://stackoverflow.com/a/49044225/6431461 if (Thor::HELP_MAPPINGS & ARGV).any? and subcommands.grep(/^#{ARGV[0]}/).empty? Kameleon.ui.debug("Apply workaround to handle the help command in #{ARGV}") Thor::HELP_MAPPINGS.each do |cmd| if match = ARGV.delete(cmd) ARGV.unshift match end end end super rescue Exception => e Kameleon.ui = Kameleon::UI::Shell.new raise e end
Calls superclass method
Public Instance Methods
Source
# File lib/kameleon/cli.rb, line 423 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 raise BuildError, "A recipe file or a persistent cache archive " \ "is required to run this command." if recipe_path.nil? if options[:dryrun] Kameleon::Engine.new(Kameleon::Recipe.new(recipe_path), options.dup.merge({no_create_build_dir: true}).freeze).dryrun elsif options[:clean] opts = Hash.new.merge options opts[:lazyload] = false opts[:fail_silently] = true engine = Kameleon::Engine.new(Recipe.new(recipe_path), opts) engine.clean(:with_checkpoint => true) elsif options[:list_checkpoints] Kameleon.ui.level = "error" engine = Kameleon::Engine.new(Recipe.new(recipe_path), options) engine.pretty_checkpoints_list else engine = Kameleon::Engine.new(Recipe.new(recipe_path), options) Kameleon.ui.info("Starting build recipe '#{recipe_path}'") start_time = Time.now.to_i engine.build total_time = Time.now.to_i - start_time Kameleon.ui.info("") Kameleon.ui.info("Successfully built '#{recipe_path}'") Kameleon.ui.info("Total duration: #{total_time} secs") end end
Source
# File lib/kameleon/cli.rb, line 461 def commands(context="main") Kameleon.ui.debug("Commands for '#{context}':") case context when "main" puts Main.all_commands.keys - ["commands"] when "repository" invoke CLI::Repository, "commands", [], [] when "template" invoke CLI::Template, "commands", [], [] end end
Source
# File lib/kameleon/cli.rb, line 295 def dag(*recipe_paths) raise ArgumentError if recipe_paths.empty? color = 0 recipes_dag = nil recipe_paths.each do |path| recipe = Kameleon::Recipe.new(path) recipes_dag = Kameleon::Engine.new(recipe, options.dup.merge({no_create_build_dir: true}).freeze).dag(recipes_dag, color, options[:recipes_only]) color += 1 end format = "canon" if options[:format] if GraphViz::Constants::FORMATS.include?(options[:format]) format = options[:format] else Kameleon.ui.warn("Unknown GraphViz format #{options[:format]}, fall back to #{format}") end else options[:file].match(/^.+\.([^\.]+)$/) do |f| if GraphViz::Constants::FORMATS.include?(f[1]) format = f[1] end end end recipes_dag.output( :"#{format}" => options[:file] ) Kameleon.ui.info("Generated GraphViz #{format} file: #{options[:file]}") end
Source
# File lib/kameleon/cli.rb, line 329 def export(recipe_path,dest_path) unless recipe_path.end_with? '.yaml' recipe_path = recipe_path + '.yaml' end # Manage global as it is not passed to env by default if options[:global] Kameleon.env.global.merge!(options[:global]) end recipe = Recipe.new(recipe_path) recipe.resolve! :strict => false recipe.all_files.uniq.each do |path| relative_path = path.relative_path_from(Kameleon.env.workspace) if relative_path.fnmatch("../*") raise if Kameleon.ui.level("verbose") raise ExportError, "Recipe '#{recipe_path}' depends on a file" \ " outside of the current directory: '#{relative_path.to_s}'" end end Kameleon.ui.info("Export recipe #{recipe_path} to directory: #{dest_path}") if File.exist?(dest_path) unless options[:add] raise if Kameleon.ui.level("verbose") raise ExportError, "Target export directory '#{dest_path}' already "\ "exists, use the --add option if you really want to export the "\ "recipe files to it (this may overwrite some existing files)" end else FileUtils.mkdir_p(dest_path) end recipe.all_files.uniq.each do |path| relative_path = path.relative_path_from(Kameleon.env.workspace) dst = File.join(dest_path, relative_path) copy_file(path, dst) end end
Source
# File lib/kameleon/cli.rb, line 258 def info(*recipe_paths) if recipe_paths.empty? if options[:from_cache].nil? raise ArgumentError else 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] end else recipe_paths.each do |path| recipe = Kameleon::Recipe.new(path) recipe.resolve! recipe.display_info(options[:relative]) end end end
Source
# File lib/kameleon/cli.rb, line 181 def list Kameleon.ui.shell.say "Workspace recipes:", :red Utils.list_recipes(Kameleon.env.workspace, options[:filter], options[:progress]) end
Source
# File lib/kameleon/cli.rb, line 190 def new(recipe_name, template_name) Kameleon.env.root_dir = Kameleon.env.repositories_path unless template_name.end_with? '.yaml' template_name = template_name + '.yaml' end unless recipe_name.end_with? '.yaml' recipe_name = recipe_name + '.yaml' end if recipe_name == template_name fail RecipeError, "Recipe path should be different from template name" end template_path = File.join(Kameleon.env.repositories_path, template_name) recipe_path = Pathname.new(Kameleon.env.workspace).join(recipe_name).to_s begin tpl = Kameleon::RecipeTemplate.new(template_path) tpl.resolve! :strict => false rescue raise if Kameleon.ui.level("verbose") raise TemplateNotFound, "Template '#{template_name}' invalid (try" \ " --verbose) or not found. To see all templates, run the command "\ "`kameleon template list`" else 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) chmod(dst, File.stat(path).mode, {:verbose=>false}) end Dir::mktmpdir do |tmp_dir| recipe_temp = File.join(tmp_dir, File.basename(recipe_path)) ## copying recipe File.open(recipe_temp, 'w+') do |file| message="Try and use extend recipe ERB: " extend_yaml_erb_list = Pathname.new(template_name).dirname.ascend.to_a.map do |p| Kameleon.env.repositories_path.join(p, Kameleon.default_values[:extend_yaml_erb]) end extend_yaml_erb_list.unshift(Kameleon.env.repositories_path.join(template_name.gsub(%r{^(.+?/)?([^/]+?)(\.yaml)?$},'\1.\2') + Kameleon.default_values[:extend_yaml_erb])) extend_yaml_erb_list.push(Pathname.new(Kameleon.erb_dirpath).join("extend.yaml.erb")) extend_yaml_erb = extend_yaml_erb_list.find do |f| Kameleon.ui.verbose(message + f.to_s) message = "-> Not found, fallback: " File.readable?(f) end Kameleon.ui.debug("Open ERB file: '#{extend_yaml_erb}'") result = ERB.new(File.open(extend_yaml_erb, 'rb') { |f| f.read }).result(binding) file.write(result) end copy_file(recipe_temp, recipe_path) end end end
Source
# File lib/kameleon/cli.rb, line 474 def source_root puts Kameleon.source_root end
Source
# File lib/kameleon/cli.rb, line 166 def version puts "Kameleon version #{Kameleon::VERSION}" end