Class: Mofa::CLI

Inherits:
Thor
  • Object
show all
Includes:
Config, Thor::Actions
Defined in:
lib/mofa/cli.rb

Constant Summary collapse

@@option_verbose =
false
@@option_debug =
false

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Config

config, load

Class Method Details

.option_debugObject



107
108
109
# File 'lib/mofa/cli.rb', line 107

def self.option_debug
  @@option_debug
end

.option_verboseObject



103
104
105
# File 'lib/mofa/cli.rb', line 103

def self.option_verbose
  @@option_verbose
end

Instance Method Details

#configObject



82
83
84
# File 'lib/mofa/cli.rb', line 82

def config
  config_print
end

#provision(cookbook_name_or_path) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/mofa/cli.rb', line 27

def provision(cookbook_name_or_path)
  set_verbosity

  cookbook_name_or_path ||= '.'

  target_filter = options[:target]
  #target_filter ||= Mofa::Config.config['profiles']['default']['target']

  token = MofaCmd.generate_token

  hostlist = Hostlist.create(target_filter, options[:service_hostlist_url], options[:concrete_target])
  cookbook = Cookbook.create(cookbook_name_or_path, token, options[:override_mofa_secrets])
  runlist_map = RunlistMap.create(cookbook, hostlist, token, options[:runlist])
  attributes_map = AttributesMap.create(cookbook, hostlist, token, options[:runlist], options[:attributes])

  cmd = ProvisionCmd.new(token, cookbook)

  cmd.hostlist = hostlist
  cmd.runlist_map = runlist_map
  cmd.attributes_map = attributes_map
  cmd.options = options

  cmd.prepare
  cmd.execute
  cmd.cleanup
end

#setupObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/mofa/cli.rb', line 88

def setup
  set_verbosity

  case
    when !File.exists?("#{ENV['HOME']}/.mofa/config.yml")
      begin
        config_create
      end until config_valid?
    else
      begin
        config_edit
      end until config_valid?
  end
end

#upload(cookbook_path) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/mofa/cli.rb', line 59

def upload(cookbook_path)
  set_verbosity

  cookbook_path ||= '.'

  token = MofaCmd.generate_token
  cookbook = Cookbook.create(cookbook_path, token)

  cmd = UploadCmd.new(token, cookbook)

  cmd.prepare
  cmd.execute
  cmd.cleanup
end

#versionObject



76
77
78
# File 'lib/mofa/cli.rb', line 76

def version
  puts VERSION
end