aboutsummaryrefslogtreecommitdiff
path: root/doc/api/ruby/example_command_line.rb
blob: 27fa07d75662e61cc089a19e26794bb681c5ca12 (plain)
1
2
3
4
5
6
7
8
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
#!/usr/bin/env ruby
# vim: set sw=4 sts=4 et tw=80 :

=begin description
Basic command line handling for most examples.
=end

require 'getoptlong'
require 'singleton'
require 'Paludis'

class ExampleCommandLine < GetoptLong
    include Singleton

    def initialize
        super(
            [ '--log-level',             GetoptLong::REQUIRED_ARGUMENT ],
            [ '--environment',     '-E', GetoptLong::REQUIRED_ARGUMENT ]
        )

        @environment = ""
        each do | opt, arg |
            case opt
            when '--log-level'
                Paludis::Log.instance.log_level = Paludis::LogLevel::Debug
            when '--environment'
                @environment = arg
            end
        end
    end

    attr_reader :environment
end