Class: Vedeu::Configuration::CLI Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns an instance of Configuration::CLI.

Parameters:

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


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

def initialize(args = [])
  @args = args
end

Instance Attribute Details

#argsObject (readonly, private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



115
116
117
# File 'lib/vedeu/configuration/cli.rb', line 115

def args
  @args
end

Class Method Details

.configure(args = []) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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)


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

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

Instance Method Details

#configurationHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Returns:

  • (Hash)


33
34
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
# File 'lib/vedeu/configuration/cli.rb', line 33

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
      Vedeu.log("Configuration::CLI interactive: true")

      options[:interactive] = true
    end

    opts.on('-I', '--noninteractive', '--standalone',
            'Run the application non-interactively; i.e. not requiring ' \
            'intervention from the user.') do
      Vedeu.log("Configuration::CLI interactive: false")

      options[:interactive] = false
    end

    opts.on('-1', '--run-once',
            'Run the application loop once.') do
      Vedeu.log("Configuration::CLI once: true")

      options[:once] = true
    end

    opts.on('-n', '--run-many',
            'Run the application loop continuously (default).') do
      Vedeu.log("Configuration::CLI once: false")

      options[:once] = false
    end

    opts.on('-c', '--cooked', 'Run application in cooked mode.') do
      Vedeu.log("Configuration::CLI terminal_mode: :cooked")

      options[:terminal_mode] = :cooked
    end

    opts.on('-r', '--raw', 'Run application in raw mode (default).') do
      Vedeu.log("Configuration::CLI terminal_mode: :raw")

      options[:terminal_mode] = :raw
    end

    opts.on('-d', '--debug', 'Run application with debugging on.') do
      Vedeu.log("Configuration::CLI debug: true")

      options[:debug] = true
    end

    opts.on('-D', '--trace', 'Run application with debugging on with ' \
                             'method and event tracing (noisy!).') do
      Vedeu.log("Configuration::CLI trace: true")

      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)
        Vedeu.log("Configuration::CLI colour_mode: #{colours.to_s}")

        options[:colour_mode] = colours

      else
        Vedeu.log("Configuration::CLI colour_mode: 8 (defaulted)")

        options[:colour_mode] = 8

      end
    end
  end
  parser.parse!(args)

  options
end

#optionsHash (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the options set via command-line arguments parsed by OptionParser, or an empty Hash if none were set or parsed.

Returns:

  • (Hash)


122
123
124
# File 'lib/vedeu/configuration/cli.rb', line 122

def options
  @_options ||= {}
end