Last active
December 1, 2020 22:38
-
-
Save vdinovi/5a679d5cbfa7a1e7acec5ff106e10d9f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # frozen_string_literal: true | |
| require "colorize" | |
| require "open3" | |
| require "optparse" | |
| USAGE = "k8-set -n NAMESPACE -p POD -c CONTAINER" | |
| CONFIGS = [:namespace, :pod, :container].freeze | |
| ENV_MAP = CONFIGS.reduce({}) { |hash, config| hash[config] = "K8_#{config.upcase}"; hash } | |
| options = {} | |
| OptionParser.new do |opts| | |
| opts.banner = "Usage: #{USAGE}".yellow | |
| opts.on("-nNAMESPACE", "--namespace=NAMESPACE", "K8 namespace") { |namespace| options[:namespace] = namespace } | |
| opts.on("-pPOD", "--pod=POD", "K8 pod") { |pod| options[:pod] = pod } | |
| opts.on("-cCONTAINER", "--container=CONTAINER", "K8 container") { |container| options[:container] = container } | |
| end.parse! | |
| options.each do |option| | |
| opt, value = option | |
| env_key = ENV_MAP[opt] | |
| puts (cmd = "sed -i.backup -E \"s/\#?export K8_POD=.*/export K8_POD=recorded-audio-processor-6d555fc69b-kdq6l/\" ~/.zshrc") | |
| unless (err = Open3.popen3("zsh", "-c", cmd) { |_stdin, _stdout, stderr, _wait_thr| stderr.read }).empty? | |
| puts "Error: #{err.yellow}" | |
| exit 1 | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment