Class: SimplyGenius::Atmos::CLI

Inherits:
Clamp::Command
  • Object
show all
Includes:
GemLogger::LoggerSupport
Defined in:
lib/simplygenius/atmos/cli.rb

Overview

The command line interface to atmos

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.descriptionObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/simplygenius/atmos/cli.rb', line 19

def self.description
  desc = <<-DESC
    Atmos version #{VERSION}
    
    Runs The atmos command line application
    
    e.g.
    
    atmos --help
  DESC
  desc.split("\n").collect(&:strip).join("\n")
end

.run(invocation_path = File.basename($PROGRAM_NAME), arguments = ARGV, context = {}) ⇒ Object



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/simplygenius/atmos/cli.rb', line 195

def run(invocation_path = File.basename($PROGRAM_NAME), arguments = ARGV, context = {})
  begin
    super
  rescue SystemExit => e
    if ! e.success?
      logger.log_exception(e, "Failure exit", level: :debug)
      logger.error(e.message)
      raise
    end
  rescue Exception => e
    logger.log_exception(e, "Unhandled exception", level: :debug)
    logger.error(e.message)
    exit!
  end
end

Instance Method Details

#default_color?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/simplygenius/atmos/cli.rb', line 62

def default_color?
   $stdout.tty?
end

#fetch_latest_versionObject



123
124
125
126
127
128
129
130
131
# File 'lib/simplygenius/atmos/cli.rb', line 123

def fetch_latest_version
  begin
    latest_ver = JSON.parse(open("https://rubygems.org/api/v1/versions/simplygenius-atmos/latest.json").read)['version']
  rescue => e
    latest_ver = "[Version Fetch Failed]"
    logger.log_exception(e, "Couldn't check latest atmos gem version", level: :debug)
  end
  latest_ver
end

#parse(arguments) ⇒ Object

hook into clamp lifecycle to force logging setup even when we are calling a subcommand



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/simplygenius/atmos/cli.rb', line 160

def parse(arguments)
  super
  if Atmos.config.nil?
    Atmos.config = Config.new(atmos_env, atmos_group)
    log = Atmos.config.is_atmos_repo? && log? ? "atmos.log" : nil
    level = :info
    level = :debug if debug?
    level = :error if quiet?

    Logging.setup_logging(level, color?, log)

    override_list.each do |o|
      k, v = o.split("=")
      v = YAML.load(v)
      logger.debug("Overriding config '#{k}' = #{v.inspect}")
      Atmos.config.[]=(k, v, additive: false)
    end

    UI.color_enabled = color?

    Atmos.config.add_user_load_path(*load_path_list)
    Atmos.config.plugin_manager.load_plugins

    # So we can show just the version with the -v flag
    if version?
      logger.info "Atmos Version #{VERSION}"
      exit(0)
    end

    version_check(VERSION)
  end
end

#version_check(atmos_version) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/simplygenius/atmos/cli.rb', line 133

def version_check(atmos_version)

  required_ver = Atmos.config["atmos.version_requirement"]
  if required_ver.present?
    case required_ver

    when "latest"
      latest_ver = fetch_latest_version

      if latest_ver != atmos_version
        raise "The atmos version (#{atmos_version}) does not match the given requirement (latest: #{latest_ver})"
      end

    when /[~<>=]*\s*[\d\.]*/
      if ! Gem::Dependency.new('', required_ver).match?('', atmos_version)
        raise "The atmos version (#{atmos_version}) does not match the given requirement (#{required_ver})"
      end

    else
      raise "Invalid atmos.version_requirement, should be 'latest' or in a gem dependency form"
    end
  end

end