Class: Vedeu::Config::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/vedeu/configuration/cli.rb

Overview

The Configuration::CLI class parses command-line arguments using OptionParser into options used by Vedeu to affect certain behaviours.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = []) ⇒ Configuration::CLI

Returns an instance of Configuration::CLI.

Parameters:

  • args (Array) (defaults to: [])


26
27
28
29
# File 'lib/vedeu/configuration/cli.rb', line 26

def initialize(args = [])
  @args    = args
  @options = {}
end

Instance Attribute Details

#argsObject (readonly, private)

Returns the value of attribute args.



127
128
129
# File 'lib/vedeu/configuration/cli.rb', line 127

def args
  @args
end

#optionsObject (readonly, private)

Returns the value of attribute options.



127
128
129
# File 'lib/vedeu/configuration/cli.rb', line 127

def options
  @options
end

Class Method Details

.configure(args = []) ⇒ Hash

Configure Vedeu via command-line arguments. Options set here via arguments override the client application configuration set via API#configure.

Parameters:

  • args (Array) (defaults to: [])

Returns:

  • (Hash)


18
19
20
# File 'lib/vedeu/configuration/cli.rb', line 18

def self.configure(args = [])
  new(args).configuration
end

Instance Method Details

#configurationHash

Returns the configuration options set up by parsing the command-line arguments passed to the client application.

Returns:

  • (Hash)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/vedeu/configuration/cli.rb', line 35

def configuration
  parser = OptionParser.new do |opts|
    opts.banner = "Usage: #{$PROGRAM_NAME} [options]"

    opts.on('-i', '--interactive',
            'Run the application in interactive mode (default).') do
      options[:interactive] = true
    end

    opts.on('-I', '--noninteractive', '--standalone',
            'Run the application non-interactively; i.e. not requiring ' \
            'intervention from the user.') do
      options[:interactive] = false
    end

    opts.on('-1', '--run-once',
            'Run the application loop once.') do
      options[:once] = true
    end

    opts.on('-n', '--run-many',
            'Run the application loop continuously (default).') do
      options[:once] = false
    end

    opts.on('-c', '--cooked', 'Run application in cooked mode.') do
      options[:terminal_mode] = :cooked
    end

    opts.on('-r', '--raw', 'Run application in raw mode (default).') do
      options[:terminal_mode] = :raw
    end

    opts.on('-d', '--debug', 'Run application with debugging on.') do
      options[:debug] = true
    end

    opts.on('-D', '--trace', 'Run application with debugging on with ' \
                             'method and event tracing (noisy!).') do
      options[:debug] = true
      options[:trace] = true
    end

    opts.on('-C', '--colour-mode [COLOURS]', Integer,
            'Run application in either `8`, `16`, `256` or `16777216` ' \
            'colour mode.') do |colours|
      if [8, 16, 256, 16777216].include?(colours)
        options[:colour_mode] = colours

      else
        options[:colour_mode] = 8

      end
    end

    opts.on('-l', '--log [FILENAME]', String,
            'Specify the path for the log file.') do |filename|
      options[:log] = filename
    end

    opts.on('--drb', 'Run application with DRb on.') do
      options[:drb] = true
    end

    opts.on('--drb-host', 'Set the hostname/IP for the DRb server.') do |hostname|
      #options[:drb]      = true
      options[:drb_host] = hostname
    end

    opts.on('--drb-port', 'Set the port for the DRb server.') do |port|
      # options[:drb]    = true
      options[:drb_port] = port
    end

    opts.on('--drb-height', 'Set the height for fake terminal of the DRb server.') do |height|
      # options[:drb]      = true
      options[:drb_height] = height
    end

    opts.on('--drb-width', 'Set the width for fake terminal of the DRb server.') do |width|
      # options[:drb]     = true
      options[:drb_width] = width
    end
  end

  parser.parse!(args)

  Vedeu::Config.log('CLI', options)
end