Module: ActiveLdap::Command

Includes:
GetTextSupport
Defined in:
lib/active_ldap/command.rb

Class Method Summary collapse

Class Method Details

.parse_options(argv = nil, version = nil) ⇒ Object



9
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
35
36
37
38
# File 'lib/active_ldap/command.rb', line 9

def parse_options(argv=nil, version=nil)
  argv ||= ARGV.dup
  options = OpenStruct.new
  opts = OptionParser.new do |opts|
    yield(opts, options)

    opts.separator ""
    opts.separator _("Common options:")

    opts.on_tail("--config=CONFIG",
                 _("Specify configuration file written as YAML")) do |file|
      require 'yaml'
      config = YAML.load(File.read(file)).symbolize_keys
      config = Base.prepare_configuration(config)
      Configuration::DEFAULT_CONFIG.update(config)
    end

    opts.on_tail("-h", "--help", _("Show this message")) do
      puts opts
      exit
    end

    opts.on_tail("--version", _("Show version")) do
      puts(version || VERSION)
      exit
    end
  end
  opts.parse!(argv)
  [argv, opts, options]
end

.read_password(prompt, input = $stdin, output = $stdout) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/active_ldap/command.rb', line 40

def read_password(prompt, input=$stdin, output=$stdout)
  output.print(prompt)
  system("/bin/stty -echo") if input.tty?
  input.gets.chomp
ensure
  system("/bin/stty echo") if input.tty?
  output.puts
end