Sha256: 205a8cf8aa1bd8df8a7193e13dd2f9fa316d98a4bca793419daa2958a6fdb96a

Contents?: true

Size: 828 Bytes

Versions: 3

Compression:

Stored size: 828 Bytes

Contents

require 'kontena/plugin/shell/command'

module Kontena::Plugin
  module Shell
    class EnvCommand < Command
      command 'env'
      description 'Show or set environment variables'
      help "Use 'env' to display all environment variables.\n" +
           "Use 'env HOME' to display the value of $HOME.\n" +
           "Use 'env KONTENA_URL=https://foo.example.com' to set an environment variable."
      completions -> (context, tokens, word) { ENV.keys.select { |k| k.start_with?(word) } }

      def execute
        if args[1] && args[1].include?('=')
          var, val = args[1].split('=', 2)
          ENV[var]=val
          Kontena::Cli::Config.reset_instance
        elsif args[1]
          puts ENV[args[1]]
        else
          puts ENV.map {|k,v| "#{k}=#{v}"}.join("\n")
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kontena-plugin-shell-0.2.0 lib/kontena/plugin/shell/commands/env.rb
kontena-plugin-shell-0.1.3 lib/kontena/plugin/shell/commands/env.rb
kontena-plugin-shell-0.1.2 lib/kontena/plugin/shell/commands/env.rb