Class: Batali::Command

Inherits:
Bogo::Cli::Command
  • Object
show all
Includes:
Bogo::Memoization
Defined in:
lib/batali/command.rb,
lib/batali/command/cache.rb,
lib/batali/command/update.rb,
lib/batali/command/display.rb,
lib/batali/command/install.rb,
lib/batali/command/resolve.rb,
lib/batali/command/configure.rb,
lib/batali/command/supermarket.rb

Overview

Customized command base for Batali

Direct Known Subclasses

Cache, Configure, Display, Install, Resolve, Supermarket, Update

Defined Under Namespace

Classes: Cache, Configure, Display, Install, Resolve, Supermarket, Update

Constant Summary collapse

DEFAULT_CONFIGURATION_FILES =
['.batali']

Instance Method Summary collapse

Constructor Details

#initialize(*_) ⇒ Command

Set UI when loading via command



21
22
23
24
# File 'lib/batali/command.rb', line 21

def initialize(*_)
  super
  Batali.ui = ui
end

Instance Method Details

#batali_fileBFile

Returns:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/batali/command.rb', line 27

def batali_file
  memoize(:batali_file) do
    # TODO: Add directory traverse searching
    path = config.fetch(:file, File.join(Dir.pwd, 'Batali'))
    ui.verbose "Loading Batali file from: #{path}"
    bfile = BFile.new(path, cache_directory)
    if(bfile.discover)
      bfile.auto_discover!(config[:environment])
    end
    bfile.data.keys.each do |key|
      unless(bfile.respond_to?(key))
        ui.warn "Unknown keyword used within Batali file: #{key.inspect}"
      end
    end
    bfile
  end
end

#cache_directory(*args) ⇒ String

Returns path to local cache.

Returns:

  • (String)

    path to local cache



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/batali/command.rb', line 59

def cache_directory(*args)
  memoize(['cache_directory', *args].join('_')) do
    directory = config.fetch(:cache_directory, File.join(Dir.home, '.batali', 'cache'))
    ui.debug "Cache directory to persist cookbooks: #{directory}"
    unless(args.empty?)
      directory = File.join(directory, *args.map(&:to_s))
    end
    FileUtils.mkdir_p(directory)
    directory
  end
end

#dry_run(action) { ... } ⇒ Object

Do not execute block if dry run

Parameters:

  • action (String)

    action to be performed

Yields:

  • block to execute



75
76
77
78
79
80
81
# File 'lib/batali/command.rb', line 75

def dry_run(action)
  if(config[:dry_run])
    ui.warn "Dry run disabled: #{action}"
  else
    yield
  end
end

#infrastructure?TrueClass, FalseClass

Returns infrastructure mode.

Returns:

  • (TrueClass, FalseClass)

    infrastructure mode



84
85
86
87
88
89
# File 'lib/batali/command.rb', line 84

def infrastructure?
  config[:infrastructure] || (
    config[:infrastructure].nil? &&
    manifest.infrastructure
  )
end

#manifestManifest

Returns:



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/batali/command.rb', line 46

def manifest
  memoize(:manifest) do
    path = File.join(
      File.dirname(
        config.fetch(:file, File.join(Dir.pwd, 'batali.manifest'))
      ), 'batali.manifest'
    )
    ui.verbose "Loading manifest file from: #{path}"
    Manifest.build(path)
  end
end