Class: EtcdTools::Cli::EtcdERB
- Inherits:
-
Object
- Object
- EtcdTools::Cli::EtcdERB
- Includes:
- Etcd
- Defined in:
- lib/etcd-tools/cli/etcd_erb.rb
Instance Method Summary collapse
-
#initialize ⇒ EtcdERB
constructor
A new instance of EtcdERB.
- #optparse ⇒ Object
Methods included from Etcd
Constructor Details
#initialize ⇒ EtcdERB
Returns a new instance of EtcdERB.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/etcd-tools/cli/etcd_erb.rb', line 32 def initialize self.optparse begin @etcd = etcd_connect @options[:url] rescue Etcd::ClusterConnectError $stderr.puts "Failed to connect to ETCD cluster" exit! 1 end begin template = EtcdTools::Erb.new @etcd, ARGF.read puts template.result rescue Exception => e $stderr.puts "Failed to parse ERB template!" $stderr.puts e. exit! 1 end end |
Instance Method Details
#optparse ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/etcd-tools/cli/etcd_erb.rb', line 10 def optparse @options = Hash.new @options[:url] = ENV['ETCDCTL_ENDPOINT'] @options[:url] ||= "http://127.0.0.1:2379" OptionParser.new do |opts| opts. = "Applies variables from ETCD onto ERB template\n\nUsage: #{$0} [OPTIONS] < template.erb > outfile" opts.separator "" opts.separator "Connection options:" opts.on("-u", "--url URL", "URL endpoint of the ETCD service (ETCDCTL_ENDPOINT envvar also applies) [DEFAULT: http://127.0.0.1:2379]") do |param| @options[:url] = param end opts.separator "" opts.separator "Common options:" opts.on_tail("-h", "--help", "show usage") do |param| puts opts exit! 0 end end.parse! end |