Class: Hiera::Backend::Eyaml::Subcommand

Inherits:
Object
  • Object
show all
Defined in:
lib/hiera/backend/eyaml/subcommand.rb

Constant Summary collapse

@@global_options =
[
 {:name          => :encrypt_method,
    :description => "Override default encryption and decryption method (default is PKCS7)", 
    :short       => 'n', 
    :default     => "pkcs7"},
 {:name          => :version,
    :description => "Show version information"},
 {:name          => :verbose,
    :description => "Be more verbose",
    :short       => 'v'},
 {:name          => :quiet,
    :description => "Be less verbose",
    :short       => 'q'},
 {:name          => :help,
    :description => "Information on how to use this command",
    :short       => 'h'}
]

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.global_optionsObject

Returns the value of attribute global_options.



11
12
13
# File 'lib/hiera/backend/eyaml/subcommand.rb', line 11

def global_options
  @global_options
end

.helptextObject

Returns the value of attribute helptext.



11
12
13
# File 'lib/hiera/backend/eyaml/subcommand.rb', line 11

def helptext
  @helptext
end

.optionsObject

Returns the value of attribute options.



11
12
13
# File 'lib/hiera/backend/eyaml/subcommand.rb', line 11

def options
  @options
end

Class Method Details

.all_optionsObject



32
33
34
35
36
37
# File 'lib/hiera/backend/eyaml/subcommand.rb', line 32

def self.all_options 
  options = @@global_options.dup
  options += self.options if self.options
  options += Plugins.options
  options
end

.attach_option(opt) ⇒ Object



39
40
41
# File 'lib/hiera/backend/eyaml/subcommand.rb', line 39

def self.attach_option opt
  self.suboptions += opt
end

.descriptionObject



102
103
104
# File 'lib/hiera/backend/eyaml/subcommand.rb', line 102

def self.description
  "no description"
end

.executeObject

Raises:

  • (StandardError)


110
111
112
# File 'lib/hiera/backend/eyaml/subcommand.rb', line 110

def self.execute
  raise StandardError, "This command is not implemented yet (#{self.to_s.split('::').last})"
end

.find(commandname = "unknown_command") ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/hiera/backend/eyaml/subcommand.rb', line 43

def self.find commandname = "unknown_command"
  begin
    require "hiera/backend/eyaml/subcommands/#{commandname.downcase}"
  rescue Exception => e
    require "hiera/backend/eyaml/subcommands/unknown_command"
    return Hiera::Backend::Eyaml::Subcommands::UnknownCommand
  end          
  command_module = Module.const_get('Hiera').const_get('Backend').const_get('Eyaml').const_get('Subcommands')
  command_class = Utils.find_closest_class :parent_class => command_module, :class_name => commandname
  command_class || Hiera::Backend::Eyaml::Subcommands::UnknownCommand
end

.hidden?Boolean



118
119
120
# File 'lib/hiera/backend/eyaml/subcommand.rb', line 118

def self.hidden?
  false
end

.parseObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/hiera/backend/eyaml/subcommand.rb', line 55

def self.parse

  me = self

  options = Trollop::options do

    version "Hiera-eyaml version " + Hiera::Backend::Eyaml::VERSION.to_s
    banner ["eyaml #{me.prettyname}: #{me.description}", me.helptext, "Options:"].compact.join("\n\n")

    me.all_options.each do |available_option|

      skeleton = {:description => "",
                  :short => :none}

      skeleton.merge! available_option
      opt skeleton[:name], 
          skeleton[:desc] || skeleton[:description],  #legacy plugins 
          :short => skeleton[:short], 
          :default => skeleton[:default], 
          :type => skeleton[:type]

    end

    stop_on Eyaml.subcommands

  end

  if options[:verbose]
    Hiera::Backend::Eyaml.verbosity_level += 1
  end

  if options[:quiet]
    Hiera::Backend::Eyaml.verbosity_level = 0
  end

  if options[:encrypt_method]
    Hiera::Backend::Eyaml.default_encryption_scheme = options[:encrypt_method]
  end

  options

end

.prettynameObject



114
115
116
# File 'lib/hiera/backend/eyaml/subcommand.rb', line 114

def self.prettyname
  Utils.snakecase self.to_s.split('::').last
end

.validate(args) ⇒ Object



98
99
100
# File 'lib/hiera/backend/eyaml/subcommand.rb', line 98

def self.validate args
  args
end