Class: EtcdTools::Cli::Etcd2Yaml
- Inherits:
-
Object
- Object
- EtcdTools::Cli::Etcd2Yaml
- Includes:
- Etcd
- Defined in:
- lib/etcd-tools/cli/etcd2yaml.rb
Instance Method Summary collapse
-
#initialize ⇒ Etcd2Yaml
constructor
A new instance of Etcd2Yaml.
- #optparse ⇒ Object
Methods included from Etcd
Constructor Details
#initialize ⇒ Etcd2Yaml
Returns a new instance of Etcd2Yaml.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/etcd-tools/cli/etcd2yaml.rb', line 36 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 hash = @etcd.get_hash @options[:root_path] puts YAML.dump hash rescue Exception => e $stderr.puts "Import failed" $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 31 32 33 34 |
# File 'lib/etcd-tools/cli/etcd2yaml.rb', line 10 def optparse @options = Hash.new @options[:url] = ENV['ETCDCTL_ENDPOINT'] @options[:url] ||= "http://127.0.0.1:2379" @options[:root_path] = "/" OptionParser.new do |opts| opts. = "Parses ETCD tree into structured YAML\n\nUsage: #{$0} [OPTIONS]" opts.separator "" opts.separator "Connection options:" opts.on("-u", "--url HOST", "URL endpoint of the ETCD service (ETCDCTL_ENDPOINT envvar also applies) [DEFAULT: http://127.0.0.1:4001]") do |param| @options[:url] = param end opts.separator "" opts.separator "Common options:" opts.on("-r", "--root-path PATH", "root PATH of ETCD tree to extract the data from [DEFAULT: /]") do |param| @options[:root_path] = param end opts.on_tail("-h", "--help", "show usage") do |param| puts opts; exit! 0 end end.parse! end |