Class: Vedeu::Config::CLI
- Inherits:
-
Object
- Object
- Vedeu::Config::CLI
- 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
- #args ⇒ Array<String> readonly protected
- #options ⇒ Hash readonly protected
Class Method Summary collapse
Instance Method Summary collapse
- #allowed_options ⇒ Array<Symbol> private
- #banner ⇒ String private
-
#colour_mode ⇒ OptionParser
private
CLI arguments:.
-
#configuration ⇒ Hash
Returns the configuration options set up by parsing the command-line arguments passed to the client application.
-
#cooked ⇒ OptionParser
private
CLI arguments:.
-
#debug ⇒ OptionParser
private
CLI arguments:.
-
#drb ⇒ OptionParser
private
CLI arguments:.
-
#drb_height ⇒ OptionParser
private
CLI arguments:.
-
#drb_host ⇒ OptionParser
private
CLI arguments:.
-
#drb_port ⇒ OptionParser
private
CLI arguments:.
-
#drb_width ⇒ OptionParser
private
CLI arguments:.
-
#fake ⇒ OptionParser
private
CLI arguments:.
-
#initialize(args = []) ⇒ Vedeu::Configuration::CLI
constructor
Returns a new instance of Vedeu::Config::CLI.
- #interactive ⇒ OptionParser private
-
#log ⇒ OptionParser
private
CLI arguments:.
- #parser ⇒ OptionParser private
-
#raw ⇒ OptionParser
private
CLI arguments:.
-
#root ⇒ OptionParser
private
CLI arguments:.
-
#run_many ⇒ OptionParser
private
CLI arguments:.
-
#run_once ⇒ OptionParser
private
CLI arguments:.
-
#setup! ⇒ void
private
Setup Vedeu using CLI configuration options for the client application.
-
#standalone ⇒ OptionParser
private
CLI arguments:.
Constructor Details
#initialize(args = []) ⇒ Vedeu::Configuration::CLI
Returns a new instance of Vedeu::Config::CLI.
Configure Vedeu via command-line arguments. Options set here via arguments override the client application configuration set via API::External#configure.
24 25 26 27 |
# File 'lib/vedeu/configuration/cli.rb', line 24 def initialize(args = []) @args = args = {} end |
Instance Attribute Details
#args ⇒ Array<String> (readonly, protected)
45 46 47 |
# File 'lib/vedeu/configuration/cli.rb', line 45 def args @args end |
#options ⇒ Hash (readonly, protected)
49 50 51 |
# File 'lib/vedeu/configuration/cli.rb', line 49 def end |
Class Method Details
.configure(args = []) ⇒ Object
12 13 14 |
# File 'lib/vedeu/configuration/cli.rb', line 12 def self.configure(args = []) new(args).configuration end |
Instance Method Details
#allowed_options ⇒ Array<Symbol> (private)
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/vedeu/configuration/cli.rb', line 67 def [ :colour_mode, :cooked, :debug, :drb, :drb_height, :drb_host, :drb_port, :drb_width, :fake, :interactive, :log, :raw, :run_many, :run_once, :root, :standalone, ] end |
#banner ⇒ String (private)
89 90 91 |
# File 'lib/vedeu/configuration/cli.rb', line 89 def parser. = "Usage: #{$PROGRAM_NAME} [options]" end |
#colour_mode ⇒ OptionParser (private)
CLI arguments:
-C, --colour-mode
98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/vedeu/configuration/cli.rb', line 98 def colour_mode parser.on('-C', '--colour-mode [COLOURS]', Integer, 'Run application in either `8`, `16`, `256` or `16777216` ' \ 'colour mode.') do |colours| if [8, 16, 256, 16_777_216].include?(colours) [:colour_mode] = colours else [:colour_mode] = 8 end end end |
#configuration ⇒ Hash
Returns the configuration options set up by parsing the command-line arguments passed to the client application.
33 34 35 36 37 38 39 |
# File 'lib/vedeu/configuration/cli.rb', line 33 def configuration setup! parser.parse!(args) Vedeu::Config.log(Esc.blue { '[cli]' }, ) end |
#cooked ⇒ OptionParser (private)
CLI arguments:
-c, --cooked
117 118 119 120 121 |
# File 'lib/vedeu/configuration/cli.rb', line 117 def cooked parser.on('-c', '--cooked', 'Run application in cooked mode.') do [:terminal_mode] = :cooked end end |
#debug ⇒ OptionParser (private)
CLI arguments:
-d, --debug
128 129 130 131 132 |
# File 'lib/vedeu/configuration/cli.rb', line 128 def debug parser.on('-d', '--debug', 'Run application with debugging on.') do [:debug] = true end end |
#drb ⇒ OptionParser (private)
CLI arguments:
--drb
139 140 141 142 143 |
# File 'lib/vedeu/configuration/cli.rb', line 139 def drb parser.on('--drb', 'Run application with DRb on.') do [:drb] = true end end |
#drb_height ⇒ OptionParser (private)
CLI arguments:
--drb-height
150 151 152 153 154 155 156 |
# File 'lib/vedeu/configuration/cli.rb', line 150 def drb_height parser.on('--drb-height', 'Set the height for fake terminal.') do |height| [:drb] = true [:drb_height] = height end end |
#drb_host ⇒ OptionParser (private)
CLI arguments:
--drb-host
163 164 165 166 167 168 169 |
# File 'lib/vedeu/configuration/cli.rb', line 163 def drb_host parser.on('--drb-host', 'Set the hostname/IP for the DRb server.') do |hostname| [:drb] = true [:drb_host] = hostname end end |
#drb_port ⇒ OptionParser (private)
CLI arguments:
--drb-port
176 177 178 179 180 181 |
# File 'lib/vedeu/configuration/cli.rb', line 176 def drb_port parser.on('--drb-port', 'Set the port for the DRb server.') do |port| [:drb] = true [:drb_port] = port end end |
#drb_width ⇒ OptionParser (private)
CLI arguments:
--drb-width
188 189 190 191 192 193 194 |
# File 'lib/vedeu/configuration/cli.rb', line 188 def drb_width parser.on('--drb-width', 'Set the width for fake terminal.') do |width| [:drb] = true [:drb_width] = width end end |
#fake ⇒ OptionParser (private)
CLI arguments:
-i, --interactive
201 202 203 204 205 |
# File 'lib/vedeu/configuration/cli.rb', line 201 def fake parser.on('-f', '--fake', 'Run application in fake mode.') do [:terminal_mode] = :fake end end |
#interactive ⇒ OptionParser (private)
208 209 210 211 212 213 |
# File 'lib/vedeu/configuration/cli.rb', line 208 def interactive parser.on('-i', '--interactive', 'Run the application in interactive mode (default).') do [:interactive] = true end end |
#log ⇒ OptionParser (private)
CLI arguments:
-l, --log
220 221 222 223 224 225 |
# File 'lib/vedeu/configuration/cli.rb', line 220 def log parser.on('-l', '--log [FILENAME]', String, 'Specify the path for the log file.') do |filename| [:log] = filename end end |
#parser ⇒ OptionParser (private)
62 63 64 |
# File 'lib/vedeu/configuration/cli.rb', line 62 def parser @parser ||= OptionParser.new end |
#raw ⇒ OptionParser (private)
CLI arguments:
-r, --raw
232 233 234 235 236 |
# File 'lib/vedeu/configuration/cli.rb', line 232 def raw parser.on('-r', '--raw', 'Run application in raw mode (default).') do [:terminal_mode] = :raw end end |
#root ⇒ OptionParser (private)
CLI arguments:
-s, --root
243 244 245 246 247 248 |
# File 'lib/vedeu/configuration/cli.rb', line 243 def root parser.on('-s', '--root []', String, 'Start the application from the specified controller.') do |c| [:root] = c end end |
#run_many ⇒ OptionParser (private)
CLI arguments:
-n, --run-many
255 256 257 258 259 260 |
# File 'lib/vedeu/configuration/cli.rb', line 255 def run_many parser.on('-n', '--run-many', 'Run the application loop continuously (default).') do [:once] = false end end |
#run_once ⇒ OptionParser (private)
CLI arguments:
-1, --run-once
267 268 269 270 271 |
# File 'lib/vedeu/configuration/cli.rb', line 267 def run_once parser.on('-1', '--run-once', 'Run the application loop once.') do [:once] = true end end |
#setup! ⇒ void (private)
This method returns an undefined value.
Setup Vedeu using CLI configuration options for the client application.
57 58 59 |
# File 'lib/vedeu/configuration/cli.rb', line 57 def setup! ([:banner] + ).each { |opt| send(opt) } end |
#standalone ⇒ OptionParser (private)
CLI arguments:
-I, --noninteractive, --standalone
278 279 280 281 282 283 284 |
# File 'lib/vedeu/configuration/cli.rb', line 278 def standalone parser.on('-I', '--noninteractive', '--standalone', 'Run the application non-interactively; ' \ 'i.e. not requiring intervention from the user.') do [:interactive] = false end end |