Class: FPM::Cookery::CLI::Command

Inherits:
FPM::Cookery::CLI show all
Defined in:
lib/fpm/cookery/cli.rb

Direct Known Subclasses

CleanCmd, InstallDepsCmd, PackageCmd, ShowDepsCmd

Instance Method Summary collapse

Instance Method Details

#configObject



89
90
91
# File 'lib/fpm/cookery/cli.rb', line 89

def config
  @config ||= FPM::Cookery::Config.from_cli(self)
end

#executeObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/fpm/cookery/cli.rb', line 66

def execute
  show_version if version?
  init_logging
  validate

  FPM::Cookery::BaseRecipe.send(:include, FPM::Cookery::BookHook)

  FPM::Cookery::Book.instance.load_recipe(recipe_file, config) do |recipe|
    packager = FPM::Cookery::Packager.new(recipe, config.to_hash)
    packager.target = FPM::Cookery::Facts.target.to_s

    exec(config, recipe, packager)
  end
end

#init_loggingObject



93
94
95
96
97
98
99
100
101
# File 'lib/fpm/cookery/cli.rb', line 93

def init_logging
  FPM::Cookery::Log.enable_debug(config.debug)

  if config.color?
    FPM::Cookery::Log.output(FPM::Cookery::Log::Output::ConsoleColor.new)
  else
    FPM::Cookery::Log.output(FPM::Cookery::Log::Output::Console.new)
  end
end

#recipe_fileObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/fpm/cookery/cli.rb', line 34

def recipe_file
  file = File.expand_path(recipe)

  # Allow giving the directory containing a recipe.rb
  if File.directory?(file) && File.exists?(File.join(file, 'recipe.rb'))
    file = File.join(file, 'recipe.rb')
  end

  file
end

#show_versionObject



81
82
83
84
85
86
87
# File 'lib/fpm/cookery/cli.rb', line 81

def show_version
  require 'fpm/version'
  require 'fpm/cookery/version'

  puts "fpm-cookery v#{FPM::Cookery::VERSION} (fpm v#{FPM::VERSION})"
  exit 0
end

#validateObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/fpm/cookery/cli.rb', line 45

def validate
  unless File.exists?(recipe_file)
    Log.error 'No recipe.rb found in the current directory, abort.'
    exit 1
  end

  # Override the detected platform.
  if platform
    FPM::Cookery::Facts.platform = platform
  end

  if target
    FPM::Cookery::Facts.target = target
  end

  if FPM::Cookery::Facts.target.nil?
    Log.error "No target given and we're unable to detect your platform"
    exit 1
  end
end