Sha256: a98fb91ad03a5343b483f9855c7e04ea2edee81c5939b86105c594c32cc5a88e

Contents?: true

Size: 1.72 KB

Versions: 4

Compression:

Stored size: 1.72 KB

Contents

require 'travis/cli'

module Travis
  module CLI
    class Init < Enable
      on('-f', '--force', 'override .travis.yml if it already exists')
      on('-k', '--skip-enable', 'do not enable project, only add .travis.yml')
      on('-p', '--print-conf', 'print generated config instead of writing to file')

      options = %w[
        script before_script after_script after_success install before_install
        compiler otp_release go jdk node_js perl php python rvm scala
        env gemfile
      ]

      options.each do |option|
        on "--#{option.gsub('_', '-')} VALUE", "sets #{option} option in .travis.yml (can be used more than once)" do |c, value|
          c.custom_config[option] &&= Array(c.custom_config[option]) << value
          c.custom_config[option] ||= value
        end
      end

      attr_writer :travis_config

      def run(language = nil, file = '.travis.yml')
        error ".travis.yml already exists, use --force to override" if File.exist?(file) and not force? and not print_conf?
        language ||= ask('Main programming language used: ') { |q| q.default = detect_language }
        self.travis_config = template(language).merge(custom_config)

        if print_conf?
          puts travis_config.to_yaml
        else
          save_travis_config(file)
          say("#{file} file created!")
        end

        super() unless skip_enable?
      end

      def custom_config
        @custom_config ||= {}
      end

      private

        def template(language)
          file = File.expand_path("../init/#{language}.yml", __FILE__)
          error "unknown language #{language}" unless File.exist? file
          YAML.load_file(file)
        end

        def detect_language
          'ruby'
        end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
travis-1.5.2 lib/travis/cli/init.rb
travis-1.5.1 lib/travis/cli/init.rb
travis-1.5.0 lib/travis/cli/init.rb
travis-1.4.0 lib/travis/cli/init.rb