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
-
#configuration ⇒ Hash
Returns the configuration options set up by parsing the command-line arguments passed to the client application.
- #cooked ⇒ OptionParser private
- #debug ⇒ OptionParser private
- #drb ⇒ OptionParser private
- #drb_height ⇒ OptionParser private
- #drb_host ⇒ OptionParser private
- #drb_port ⇒ OptionParser private
- #drb_width ⇒ OptionParser private
-
#initialize(args = []) ⇒ Configuration::CLI
constructor
Configure Vedeu via command-line arguments.
- #interactive ⇒ OptionParser private
- #log ⇒ OptionParser private
- #parser ⇒ OptionParser private
- #raw ⇒ OptionParser private
- #run_many ⇒ OptionParser private
- #run_once ⇒ OptionParser private
-
#setup! ⇒ void
private
Setup Vedeu using CLI configuration options for the client application.
- #standalone ⇒ OptionParser private
- #trace ⇒ OptionParser private
Constructor Details
#initialize(args = []) ⇒ Configuration::CLI
Configure Vedeu via command-line arguments. Options set here via arguments override the client application configuration set via API#configure.
20 21 22 23 |
# File 'lib/vedeu/configuration/cli.rb', line 20 def initialize(args = []) @args = args = {} end |
Instance Attribute Details
#args ⇒ Array<String> (readonly, protected)
41 42 43 |
# File 'lib/vedeu/configuration/cli.rb', line 41 def args @args end |
#options ⇒ Hash (readonly, protected)
45 46 47 |
# File 'lib/vedeu/configuration/cli.rb', line 45 def end |
Class Method Details
.configure(args = []) ⇒ Object
10 11 12 |
# File 'lib/vedeu/configuration/cli.rb', line 10 def self.configure(args = []) new(args).configuration end |
Instance Method Details
#allowed_options ⇒ Array<Symbol> (private)
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/vedeu/configuration/cli.rb', line 62 def [ :colour_mode, :cooked, :debug, :drb, :drb_height, :drb_host, :drb_port, :drb_width, :interactive, :log, :raw, :run_many, :run_once, :standalone, :trace, ] end |
#banner ⇒ String (private)
83 84 85 |
# File 'lib/vedeu/configuration/cli.rb', line 83 def parser. = "Usage: #{$PROGRAM_NAME} [options]" end |
#colour_mode ⇒ OptionParser (private)
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/vedeu/configuration/cli.rb', line 88 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.
29 30 31 32 33 34 35 |
# File 'lib/vedeu/configuration/cli.rb', line 29 def configuration setup! parser.parse!(args) Vedeu::Config.log(Esc.blue { '[cli]' }, ) end |
#cooked ⇒ OptionParser (private)
103 104 105 106 107 |
# File 'lib/vedeu/configuration/cli.rb', line 103 def cooked parser.on('-c', '--cooked', 'Run application in cooked mode.') do [:terminal_mode] = :cooked end end |
#debug ⇒ OptionParser (private)
110 111 112 113 114 |
# File 'lib/vedeu/configuration/cli.rb', line 110 def debug parser.on('-d', '--debug', 'Run application with debugging on.') do [:debug] = true end end |
#drb ⇒ OptionParser (private)
117 118 119 120 121 |
# File 'lib/vedeu/configuration/cli.rb', line 117 def drb parser.on('--drb', 'Run application with DRb on.') do [:drb] = true end end |
#drb_height ⇒ OptionParser (private)
124 125 126 127 128 129 130 |
# File 'lib/vedeu/configuration/cli.rb', line 124 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)
133 134 135 136 137 138 139 |
# File 'lib/vedeu/configuration/cli.rb', line 133 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)
142 143 144 145 146 147 |
# File 'lib/vedeu/configuration/cli.rb', line 142 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)
150 151 152 153 154 155 156 |
# File 'lib/vedeu/configuration/cli.rb', line 150 def drb_width parser.on('--drb-width', 'Set the width for fake terminal.') do |width| [:drb] = true [:drb_width] = width end end |
#interactive ⇒ OptionParser (private)
159 160 161 162 163 164 |
# File 'lib/vedeu/configuration/cli.rb', line 159 def interactive parser.on('-i', '--interactive', 'Run the application in interactive mode (default).') do [:interactive] = true end end |
#log ⇒ OptionParser (private)
167 168 169 170 171 172 |
# File 'lib/vedeu/configuration/cli.rb', line 167 def log parser.on('-l', '--log [FILENAME]', String, 'Specify the path for the log file.') do |filename| [:log] = filename end end |
#parser ⇒ OptionParser (private)
57 58 59 |
# File 'lib/vedeu/configuration/cli.rb', line 57 def parser @parser ||= OptionParser.new end |
#raw ⇒ OptionParser (private)
175 176 177 178 179 |
# File 'lib/vedeu/configuration/cli.rb', line 175 def raw parser.on('-r', '--raw', 'Run application in raw mode (default).') do [:terminal_mode] = :raw end end |
#run_many ⇒ OptionParser (private)
182 183 184 185 186 187 |
# File 'lib/vedeu/configuration/cli.rb', line 182 def run_many parser.on('-n', '--run-many', 'Run the application loop continuously (default).') do [:once] = false end end |
#run_once ⇒ OptionParser (private)
190 191 192 193 194 |
# File 'lib/vedeu/configuration/cli.rb', line 190 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.
52 53 54 |
# File 'lib/vedeu/configuration/cli.rb', line 52 def setup! ([:banner] + ).each { |opt| send(opt) } end |
#standalone ⇒ OptionParser (private)
197 198 199 200 201 202 203 |
# File 'lib/vedeu/configuration/cli.rb', line 197 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 |
#trace ⇒ OptionParser (private)
206 207 208 209 210 211 212 |
# File 'lib/vedeu/configuration/cli.rb', line 206 def trace parser.on('-D', '--trace', 'Run application with debugging on with ' \ 'method and event tracing (noisy!).') do [:debug] = true [:trace] = true end end |