Module: ActiveSambaLdap::Command
- Includes:
- GetTextSupport
- Defined in:
- lib/active_samba_ldap/command.rb
Class Method Summary collapse
- .default_configuration_files ⇒ Object
- .parse_options(argv = nil) ⇒ Object
- .read_configuration_files(files) ⇒ Object
- .read_password(prompt, input = $stdin, output = $stdout) ⇒ Object
Methods included from GetTextSupport
Class Method Details
.default_configuration_files ⇒ Object
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 |
# File 'lib/active_samba_ldap/command.rb', line 63 def default_configuration_files configuration_files = File.join(File.dirname(__FILE__), "configuration_files") if File.exists?(configuration_files) files = File.readlines(configuration_files).collect do |line| line.strip end.reject do |line| line.empty? or /^#/ =~ line end else files = [ "/etc/activesambaldap/config.yaml", "/etc/activesambaldap/bind.yaml", ] end begin configuration_files_for_user = [ File.(File.join("~", ".activesambaldap.conf")), File.(File.join("~", ".activesambaldap.bind")), ] files.concat(configuration_files_for_user) rescue ArgumentError end files end |
.parse_options(argv = nil) ⇒ Object
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 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/active_samba_ldap/command.rb', line 11 def (argv=nil) argv ||= ARGV.dup = OpenStruct.new configuration_files = default_configuration_files opts = OptionParser.new do |opts| yield(opts, ) opts.separator("") opts.separator(_("Common options:")) opts.on_tail("--config=CONFIG", _("Specify configuration file"), _("Default configuration files:"), *configuration_files.collect {|x| " #{x}"}) do |file| configuration_files << file end opts.on_tail("-h", "--help", _("Show this message")) do puts opts exit end opts.on_tail("--version", _("Show version")) do puts VERSION exit end end begin opts.parse!(argv) rescue OptionParser::ParseError $stderr.puts($!) $stderr.puts(opts) exit 1 end read_configuration_files(configuration_files) [argv, opts, ] end |
.read_configuration_files(files) ⇒ Object
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/active_samba_ldap/command.rb', line 89 def read_configuration_files(files) return if files.empty? Base.configurations = files.inject({}) do |result, file| if File.readable?(file) result.merge(Configuration.read(file)) else result end end end |
.read_password(prompt, input = $stdin, output = $stdout) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/active_samba_ldap/command.rb', line 52 def read_password(prompt, input=$stdin, output=$stdout) output.print prompt system "/bin/stty -echo" if input.tty? password = input.gets password = password.chomp if password password ensure system "/bin/stty echo" if input.tty? output.puts end |