Skip to content

Commit

Permalink
fix: don't parse input when piping
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyrremann committed Mar 30, 2022
1 parent 1eed4cb commit 613b66f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions eksporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
require 'optparse'
require 'yaml'

ARGV << '-h' if ARGV.empty?

OPTIONS = {}
OptionParser.new do |opts|
OPTIONPARSER = OptionParser.new do |opts|
opts.banner = '''Usage: kubectl eksporter <resource> <name>
Export resources and removes a pre-defined set of fields for later import
Expand All @@ -29,7 +27,7 @@
opts.on("--drop field1,field2,field3", Array, "Drop fields that normally are spared")
opts.on("-n", "--namespace namespace", String, "If present, the namespace scope for this CLI request")
opts.on("-l", "--selector label", String, "Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)")
end.parse!(into: OPTIONS)
end

def delete_field(resource, fields)
field = fields.shift
Expand Down Expand Up @@ -77,6 +75,9 @@ def main
input = ARGF.read
resources = YAML.load(input)
else
ARGV << '-h' if ARGV.empty?
OPTIONPARSER.parse!(into: OPTIONS)

args = ARGV.join(' ')
cmd = "kubectl get #{args} -o yaml"
cmd += " -n #{OPTIONS[:namespace]}" if OPTIONS.has_key?(:namespace)
Expand Down

0 comments on commit 613b66f

Please sign in to comment.