Sha256: dba6e2c1b2bcede0bb25ad76db4d6f2cf31c2543d0fdd9c595a754cdd4fa3a08

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

require "thor"
require "yaml"

class JenkinsCron::CLI < Thor
  class_option :config, type: :string, aliases: "-c", default: "config/jenkins.yml", desc: "Jenkins config file"

  desc "update NAME", "Update Jenkins using config/schedule/NAME.rb"
  def update(name)
    schedule = JenkinsCron::Schedule.load(name, schedule_file(name))
    jenkins.update(schedule)
  end

  desc "version", "Display jenkins_cron version"
  map ["-v", "--version"] => :version
  def version
    puts JenkinsCron::VERSION
  end

  private

  def jenkins
    @jenkins ||= JenkinsCron::Jenkins.new(config)
  end

  def config
    @config ||= YAML.load_file(config_file)
  rescue SyntaxError
    error("Can't parse config file: #{config_file}")
  end

  def config_file
    @config_file ||= options[:config]
    unless File.exists? @config_file
      error("Can't find config file: #{@config_file}")
    end
    @config_file
  end

  def schedule_file(name)
    file = "config/schedule/#{name}.rb"
    unless File.exists? file
      error("Can't find schedule file: #{file}")
    end
    file
  end

  def error(message)
    puts "ERROR: #{message}"
    exit 1
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jenkins_cron-0.0.3 lib/jenkins_cron/cli.rb
jenkins_cron-0.0.2 lib/jenkins_cron/cli.rb