Sha256: b35c6c265d7c54fa8cbd9a8d7a65af77a1793167db9dd5e4c0749e43592bf6db

Contents?: true

Size: 1.64 KB

Versions: 40

Compression:

Stored size: 1.64 KB

Contents

require 'travis/cli'
require 'shellwords'

module Travis
  module CLI
    class Env < RepoCommand
      on('-P', '--[no-]public',  'make new values public')
      on('-p', '--[no-]private', 'make new values private') { |c,v| c.public = !v }
      on('-u', '--[no-]unescape', 'do not escape values')

      description "show or modify build environment variables"
      subcommands :list, :set, :unset, :copy

      def setup
        super
        authenticate
        error "not allowed to access environment variables for #{color(repository.slug, :bold)}" unless repository.admin?
      end

      def set(name, value)
        options ||= { :public => public } if public != nil
        say color('[+] ', [:green, :bold]) + "setting environment variable #{color "$#{name}", :info}"
        value = Shellwords.escape(value) unless unescape?
        env_vars.upsert(name, value, options || {})
      end

      def copy(*names)
        names.each do |name|
          if ENV.include? name
            set(name, ENV[name])
          else
            warn "missing in current environment: #{color "$#{name}", :bold}"
          end
        end
      end

      def unset(*names)
        env_vars.each do |var|
          next unless names.include? var.name
          say color('[x] ', [:red, :bold]) + "removing environment variable #{color "$#{var.name}", :info}"
          var.delete
        end
      end

      def list
        say color("# environment variables for #{color repository.slug, :bold}", :info)
        env_vars.each { |v| say "#{v.name}=" << color(v.value || "[secure]", :bold) }
      end

      def env_vars
        repository.env_vars
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
travis-1.7.3.travis.641.5 lib/travis/cli/env.rb
travis-1.7.3.travis.640.5 lib/travis/cli/env.rb
travis-1.7.3.travis.637.5 lib/travis/cli/env.rb
travis-1.7.2 lib/travis/cli/env.rb
travis-1.7.2.travis.636.5 lib/travis/cli/env.rb
travis-1.7.2.travis.635.5 lib/travis/cli/env.rb
travis-1.7.2.travis.634.5 lib/travis/cli/env.rb
travis-1.7.2.travis.633.5 lib/travis/cli/env.rb
travis-1.7.2.travis.632.5 lib/travis/cli/env.rb
travis-1.7.2.travis.630.5 lib/travis/cli/env.rb
travis-1.7.2.travis.627.5 lib/travis/cli/env.rb
travis-1.7.2.travis.626.5 lib/travis/cli/env.rb
travis-1.7.2.travis.625.5 lib/travis/cli/env.rb
travis-1.7.2.travis.623.5 lib/travis/cli/env.rb
travis-1.7.2.travis.621.5 lib/travis/cli/env.rb
travis-1.7.1 lib/travis/cli/env.rb
travis-1.7.1.travis.613.5 lib/travis/cli/env.rb
travis-1.7.0 lib/travis/cli/env.rb
travis-1.6.18.travis.612.5 lib/travis/cli/env.rb
travis-1.6.18.travis.611.5 lib/travis/cli/env.rb