Class: Detroit::Toolchain::CLI
Overview
The CLI class.
Class Method Summary collapse
-
.execute(argv = ARGV) ⇒ Object
argv - Command line arguments.
Instance Method Summary collapse
-
#application(options = {}) ⇒ Object
Returns Runner instance given options.
- #assembly ⇒ Object
- #assembly=(name) ⇒ Object
- #execute(*argv) ⇒ Object
- #force ⇒ Object
- #force=(boolean) ⇒ Object
-
#initialize ⇒ CLI
constructor
Run the command line interface.
- #multitask ⇒ Object
- #multitask=(boolean) ⇒ Object
- #option_assembly ⇒ void
- #option_config ⇒ Object
- #option_debug ⇒ void
- #option_force ⇒ void
- #option_help ⇒ void
- #option_loadpath ⇒ void
- #option_multitask ⇒ void
-
#option_parser ⇒ Object
Create command line option parser.
- #option_quiet ⇒ void
- #option_skip ⇒ void
- #option_toolchain ⇒ void
- #option_trace ⇒ void
- #option_trial ⇒ void
- #option_verbose ⇒ void
- #option_warn ⇒ void
-
#options ⇒ Object
Command line options.
- #quiet ⇒ Object
- #quiet=(boolean) ⇒ Object
- #skip ⇒ Object
- #toolchains ⇒ Object
- #trace ⇒ Object
- #trace=(boolean) ⇒ Object
- #trial ⇒ Object
- #trial=(boolean) ⇒ Object
-
#usage ⇒ OptionParser
Cached instance of OptionParser.
- #usage_banner ⇒ String
- #verbose ⇒ Object
- #verbose=(boolean) ⇒ Object
Constructor Details
#initialize ⇒ CLI
Run the command line interface.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/detroit/toolchain/cli.rb', line 37 def initialize @options = { :toolchains => [], :assembly => nil, :trace => nil, :trial => nil, :debug => nil, :quiet => nil, :verbose => nil, :force => nil, :multitask => nil, :skip => [] } end |
Class Method Details
.execute(argv = ARGV) ⇒ Object
argv - Command line arguments.
32 33 34 |
# File 'lib/detroit/toolchain/cli.rb', line 32 def self.execute(argv=ARGV) new.execute(*argv) end |
Instance Method Details
#application(options = {}) ⇒ Object
Returns Runner instance given options.
85 86 87 |
# File 'lib/detroit/toolchain/cli.rb', line 85 def application(={}) Runner.new() end |
#assembly ⇒ Object
115 116 117 |
# File 'lib/detroit/toolchain/cli.rb', line 115 def assembly @options[:assembly] end |
#assembly=(name) ⇒ Object
120 121 122 |
# File 'lib/detroit/toolchain/cli.rb', line 120 def assembly=(name) @options[:assembly] = name.to_sym end |
#execute(*argv) ⇒ Object
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 |
# File 'lib/detroit/toolchain/cli.rb', line 53 def execute(*argv) #if /\.assembly$/ =~ argv[0] # job = argv[1] # begin # application(cli_options).runscript(argv[0], job) # rescue => error # $stderr.puts error.message # exit -1 # end #else option_parser.parse!(argv) if argv.empty? # TODO: What about a defualt destination, e.g. test? $stderr.puts "No assembly destination given." exit -1 end if $DEBUG application().start(*argv) else begin application().start(*argv) rescue => error $stderr.puts error. exit -1 end end end |
#force ⇒ Object
125 126 127 |
# File 'lib/detroit/toolchain/cli.rb', line 125 def force @options[:force] end |
#force=(boolean) ⇒ Object
130 131 132 |
# File 'lib/detroit/toolchain/cli.rb', line 130 def force=(boolean) @options[:force] = !!boolean end |
#multitask ⇒ Object
105 106 107 |
# File 'lib/detroit/toolchain/cli.rb', line 105 def multitask @options[:multitask] end |
#multitask=(boolean) ⇒ Object
110 111 112 |
# File 'lib/detroit/toolchain/cli.rb', line 110 def multitask=(boolean) @options[:multitask] = !!boolean end |
#option_assembly ⇒ void
This method returns an undefined value.
214 215 216 217 218 |
# File 'lib/detroit/toolchain/cli.rb', line 214 def option_assembly usage.on('-a', '--assembly=NAME', "Select assembly. Default is `standard'.") do |a| self.assembly = a end end |
#option_config ⇒ Object
309 310 311 312 313 314 |
# File 'lib/detroit/toolchain/cli.rb', line 309 def option_config usage.on_tail('-c', '--config TOOL', "Produce a configuration template.") do |tool| puts application.config_template(tool).to_yaml exit end end |
#option_debug ⇒ void
This method returns an undefined value.
283 284 285 286 287 |
# File 'lib/detroit/toolchain/cli.rb', line 283 def option_debug usage.on('--debug', "Run with $DEBUG set to true.") do $DEBUG = true end end |
#option_force ⇒ void
This method returns an undefined value.
267 268 269 270 271 |
# File 'lib/detroit/toolchain/cli.rb', line 267 def option_force usage.on('-F', '--force', "Force operations.") do self.force = true end end |
#option_help ⇒ void
This method returns an undefined value.
297 298 299 300 301 302 303 304 305 306 |
# File 'lib/detroit/toolchain/cli.rb', line 297 def option_help usage.on_tail('--help [TOOL]', "Display this help message.") do |tool| if tool application.display_help(tool) else puts usage end exit end end |
#option_loadpath ⇒ void
This method returns an undefined value.
274 275 276 277 278 279 280 |
# File 'lib/detroit/toolchain/cli.rb', line 274 def option_loadpath usage.on('-I=PATH', "Add directory to $LOAD_PATH") do |dirs| dirs.to_list.each do |dir| $LOAD_PATH.unshift(dir) end end end |
#option_multitask ⇒ void
This method returns an undefined value.
207 208 209 210 211 |
# File 'lib/detroit/toolchain/cli.rb', line 207 def option_multitask usage.on('-m', '--multitask', "Run work elements in parallel.") do self.multitask = true end end |
#option_parser ⇒ Object
Create command line option parser.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/detroit/toolchain/cli.rb', line 175 def option_parser option_multitask option_assembly option_toolchain option_skip option_trial option_trace option_loadpath option_force option_verbose option_quiet option_config option_debug option_warn option_help usage end |
#option_quiet ⇒ void
This method returns an undefined value.
260 261 262 263 264 |
# File 'lib/detroit/toolchain/cli.rb', line 260 def option_quiet usage.on('-q', '--quiet', "Run silently.") do self.quiet = true end end |
#option_skip ⇒ void
This method returns an undefined value.
228 229 230 231 232 |
# File 'lib/detroit/toolchain/cli.rb', line 228 def option_skip usage.on('-S', '--skip [NAME]', 'Skip a tool instance.') do |skip| self.skip << skip end end |
#option_toolchain ⇒ void
This method returns an undefined value.
221 222 223 224 225 |
# File 'lib/detroit/toolchain/cli.rb', line 221 def option_toolchain usage.on('-t', '--toolchain [FILE]', 'Use specific toolchain file(s).') do |file| self.toolchains << file end end |
#option_trace ⇒ void
This method returns an undefined value.
243 244 245 246 247 248 |
# File 'lib/detroit/toolchain/cli.rb', line 243 def option_trace usage.on('--trace', "Run in TRACE mode.") do #$TRACE = true self.trace = true end end |
#option_trial ⇒ void
This method returns an undefined value.
235 236 237 238 239 240 |
# File 'lib/detroit/toolchain/cli.rb', line 235 def option_trial usage.on('--trial', "Run in TRIAL mode (no disk writes).") do #$TRIAL = true self.trial = true end end |
#option_verbose ⇒ void
Do we really need verbose?
This method returns an undefined value.
253 254 255 256 257 |
# File 'lib/detroit/toolchain/cli.rb', line 253 def option_verbose usage.on('--verbose', "Provide extra output.") do self.verbose = true end end |
#option_warn ⇒ void
This method returns an undefined value.
290 291 292 293 294 |
# File 'lib/detroit/toolchain/cli.rb', line 290 def option_warn usage.on('--warn', "Run with $VERBOSE set to true.") do $VERBOSE = true # wish this were called $WARN end end |
#options ⇒ Object
Command line options.
90 91 92 |
# File 'lib/detroit/toolchain/cli.rb', line 90 def @options end |
#quiet ⇒ Object
155 156 157 |
# File 'lib/detroit/toolchain/cli.rb', line 155 def quiet @options[:quiet] end |
#quiet=(boolean) ⇒ Object
160 161 162 |
# File 'lib/detroit/toolchain/cli.rb', line 160 def quiet=(boolean) @options[:quiet] = !!boolean end |
#skip ⇒ Object
100 101 102 |
# File 'lib/detroit/toolchain/cli.rb', line 100 def skip @options[:skip] end |
#toolchains ⇒ Object
95 96 97 |
# File 'lib/detroit/toolchain/cli.rb', line 95 def toolchains @options[:toolchains] end |
#trace ⇒ Object
145 146 147 |
# File 'lib/detroit/toolchain/cli.rb', line 145 def trace @options[:trace] end |
#trace=(boolean) ⇒ Object
150 151 152 |
# File 'lib/detroit/toolchain/cli.rb', line 150 def trace=(boolean) @options[:trace] = !!boolean end |
#trial ⇒ Object
135 136 137 |
# File 'lib/detroit/toolchain/cli.rb', line 135 def trial @options[:trial] end |
#trial=(boolean) ⇒ Object
140 141 142 |
# File 'lib/detroit/toolchain/cli.rb', line 140 def trial=(boolean) @options[:trial] = !!boolean end |
#usage ⇒ OptionParser
Cached instance of OptionParser.
197 198 199 |
# File 'lib/detroit/toolchain/cli.rb', line 197 def usage @usage ||= OptionParser.new end |
#usage_banner ⇒ String
202 203 204 |
# File 'lib/detroit/toolchain/cli.rb', line 202 def usage. = "Usage: detroit [<track>:]<stop> [options]" end |
#verbose ⇒ Object
165 166 167 |
# File 'lib/detroit/toolchain/cli.rb', line 165 def verbose @options[:quiet] end |
#verbose=(boolean) ⇒ Object
170 171 172 |
# File 'lib/detroit/toolchain/cli.rb', line 170 def verbose=(boolean) @options[:verbose] = !!boolean end |