Class: DreamOps::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/dream-ops/cli.rb

Defined Under Namespace

Classes: Runner

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Cli

Returns a new instance of Cli.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/dream-ops/cli.rb', line 52

def initialize(*args)
  super(*args)

  if @options[:debug]
    ENV["DREAMOPS_DEBUG"] = "true"
    DreamOps.logger.level = ::Logger::DEBUG
    Thread.report_on_exception = true
  else
    Thread.report_on_exception = false
    Berkshelf.ui.mute!
  end

  if @options[:quiet]
    DreamOps.ui.mute!
  end

  DreamOps.set_format @options[:format]

  if !@options[:ssh_key].empty?
    DreamOps.set_ssh_key @options[:ssh_key]
  end

  if !@options[:aws_profile].empty?
    DreamOps.use_aws_profile @options[:aws_profile]
  end

  @options = options.dup # unfreeze frozen options Hash from Thor
end

Class Method Details

.dispatch(meth, given_args, given_opts, config) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/dream-ops/cli.rb', line 36

def dispatch(meth, given_args, given_opts, config)
  if given_args.length > 1 && !(given_args & Thor::HELP_MAPPINGS).empty?
    command = given_args.first

    if subcommands.include?(command)
      super(meth, [command, "help"].compact, nil, config)
    else
      super(meth, ["help", command].compact, nil, config)
    end
  else
    super
    DreamOps.formatter.cleanup_hook unless config[:current_command].name == "help"
  end
end

.exit_on_failure?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/dream-ops/cli.rb', line 115

def self.exit_on_failure?
  false
end

Instance Method Details

#deploy(type) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/dream-ops/cli.rb', line 134

def deploy(type)
  deployer = nil
  DreamOps.set_force_setup options[:force_setup]
  targets = options[:targets]
  args = [*targets]

  if type == 'opsworks'
    deployer = OpsWorksDeployer.new
  elsif type == 'solo'
    deployer = SoloDeployer.new
  else
    DreamOps.ui.error "Deployment of type '#{type}' is not supported"
    exit(1)
  end

  if !deployer.nil?
    deployer.deploy(*args)
  end
end

#init(type) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/dream-ops/cli.rb', line 165

def init(type)
  initializer = nil
  targets = options[:targets]
  args = [*targets]

  if type == 'solo'
    initializer = SoloInitializer.new
  else
    DreamOps.ui.error "Type '#{type}' is not supported"
    exit(1)
  end

  if !initializer.nil?
    initializer.init(*args, options[:dryrun])
  end
end

#versionObject



120
121
122
# File 'lib/dream-ops/cli.rb', line 120

def version
  DreamOps.formatter.version
end