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 ⇒ Object
readonly
private
Returns the value of attribute args.
-
#options ⇒ Object
readonly
private
Returns the value of attribute options.
Class Method Summary collapse
-
.configure(args = []) ⇒ Hash
Configure Vedeu via command-line arguments.
Instance Method Summary collapse
-
#configuration ⇒ Hash
Returns the configuration options set up by parsing the command-line arguments passed to the client application.
-
#initialize(args = []) ⇒ Configuration::CLI
constructor
Returns an instance of Configuration::CLI.
Constructor Details
#initialize(args = []) ⇒ Configuration::CLI
Returns an instance of Configuration::CLI.
26 27 28 29 |
# File 'lib/vedeu/configuration/cli.rb', line 26 def initialize(args = []) @args = args = {} end |
Instance Attribute Details
#args ⇒ Object (readonly, private)
Returns the value of attribute args.
127 128 129 |
# File 'lib/vedeu/configuration/cli.rb', line 127 def args @args end |
#options ⇒ Object (readonly, private)
Returns the value of attribute options.
127 128 129 |
# File 'lib/vedeu/configuration/cli.rb', line 127 def 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.
18 19 20 |
# File 'lib/vedeu/configuration/cli.rb', line 18 def self.configure(args = []) new(args).configuration end |
Instance Method Details
#configuration ⇒ Hash
Returns the configuration options set up by parsing the command-line arguments passed to the client application.
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. = "Usage: #{$PROGRAM_NAME} [options]" opts.on('-i', '--interactive', 'Run the application in interactive mode (default).') do [:interactive] = true end opts.on('-I', '--noninteractive', '--standalone', 'Run the application non-interactively; i.e. not requiring ' \ 'intervention from the user.') do [:interactive] = false end opts.on('-1', '--run-once', 'Run the application loop once.') do [:once] = true end opts.on('-n', '--run-many', 'Run the application loop continuously (default).') do [:once] = false end opts.on('-c', '--cooked', 'Run application in cooked mode.') do [:terminal_mode] = :cooked end opts.on('-r', '--raw', 'Run application in raw mode (default).') do [:terminal_mode] = :raw end opts.on('-d', '--debug', 'Run application with debugging on.') do [:debug] = true end opts.on('-D', '--trace', 'Run application with debugging on with ' \ 'method and event tracing (noisy!).') do [:debug] = true [: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) [:colour_mode] = colours else [:colour_mode] = 8 end end opts.on('-l', '--log [FILENAME]', String, 'Specify the path for the log file.') do |filename| [:log] = filename end opts.on('--drb', 'Run application with DRb on.') do [:drb] = true end opts.on('--drb-host', 'Set the hostname/IP for the DRb server.') do |hostname| #options[:drb] = true [:drb_host] = hostname end opts.on('--drb-port', 'Set the port for the DRb server.') do |port| # options[:drb] = true [:drb_port] = port end opts.on('--drb-height', 'Set the height for fake terminal of the DRb server.') do |height| # options[:drb] = true [:drb_height] = height end opts.on('--drb-width', 'Set the width for fake terminal of the DRb server.') do |width| # options[:drb] = true [:drb_width] = width end end parser.parse!(args) Vedeu::Config.log('CLI', ) end |