lib/travis/cli/env.rb in travis-1.7.3.travis.641.5 vs lib/travis/cli/env.rb in travis-1.7.3.travis.644.5
- old
+ new
@@ -2,16 +2,17 @@
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('-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')
+ on('-f', '--force', 'do not ask for confirmation when clearing out all variables')
description "show or modify build environment variables"
- subcommands :list, :set, :unset, :copy
+ subcommands :list, :set, :unset, :copy, :clear
def setup
super
authenticate
error "not allowed to access environment variables for #{color(repository.slug, :bold)}" unless repository.admin?
@@ -33,11 +34,21 @@
end
end
end
def unset(*names)
+ remove_vars { |var| names.include? var.name }
+ end
+
+ def clear
+ exit if env_vars.empty?
+ exit 1 if interactive? and not force? and not danger_zone? "Clear out all env variables for #{color(repository.slug, :bold)}?"
+ remove_vars
+ end
+
+ def remove_vars
env_vars.each do |var|
- next unless names.include? var.name
+ next if block_given? and not yield(var)
say color('[x] ', [:red, :bold]) + "removing environment variable #{color "$#{var.name}", :info}"
var.delete
end
end
\ No newline at end of file