Class: Vedeu::Configuration::CLI Private
- Inherits:
-
Object
- Object
- Vedeu::Configuration::CLI
- 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
- #args ⇒ Object readonly private private
Class Method Summary collapse
-
.configure(args = []) ⇒ Hash
private
Configure Vedeu via command-line arguments.
Instance Method Summary collapse
-
#configuration ⇒ Hash
private
Returns the configuration options set up by parsing the command-line arguments passed to the client application.
-
#initialize(args = []) ⇒ Configuration::CLI
constructor
private
Returns an instance of Configuration::CLI.
-
#options ⇒ Hash
private
private
Returns the options set via command-line arguments parsed by OptionParser, or an empty Hash if none were set or parsed.
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.
25 26 27 |
# File 'lib/vedeu/configuration/cli.rb', line 25 def initialize(args = []) @args = args end |
Instance Attribute Details
#args ⇒ Object (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.
17 18 19 |
# File 'lib/vedeu/configuration/cli.rb', line 17 def self.configure(args = []) new(args = []).configuration end |
Instance Method Details
#configuration ⇒ 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.
Returns the configuration options set up by parsing the command-line arguments passed to the client application.
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. = "Usage: #{$PROGRAM_NAME} [options]" opts.on('-i', '--interactive', 'Run the application in interactive mode (default).') do Vedeu.log("Configuration::CLI interactive: true") [: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") [:interactive] = false end opts.on('-1', '--run-once', 'Run the application loop once.') do Vedeu.log("Configuration::CLI once: true") [:once] = true end opts.on('-n', '--run-many', 'Run the application loop continuously (default).') do Vedeu.log("Configuration::CLI once: false") [:once] = false end opts.on('-c', '--cooked', 'Run application in cooked mode.') do Vedeu.log("Configuration::CLI terminal_mode: :cooked") [:terminal_mode] = :cooked end opts.on('-r', '--raw', 'Run application in raw mode (default).') do Vedeu.log("Configuration::CLI terminal_mode: :raw") [:terminal_mode] = :raw end opts.on('-d', '--debug', 'Run application with debugging on.') do Vedeu.log("Configuration::CLI debug: true") [: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") [: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) Vedeu.log("Configuration::CLI colour_mode: #{colours.to_s}") [:colour_mode] = colours else Vedeu.log("Configuration::CLI colour_mode: 8 (defaulted)") [:colour_mode] = 8 end end end parser.parse!(args) end |
#options ⇒ Hash (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.
122 123 124 |
# File 'lib/vedeu/configuration/cli.rb', line 122 def ||= {} end |