Module: Brite::Command
Overview
Brite command module.
Instance Method Summary collapse
-
#call(*argv) ⇒ Object
Execute command.
-
#controller(options) ⇒ Controller
Create an instance of Brite::Controller given controller options.
-
#options_general(parser, options) ⇒ Object
Add ‘–trace`, `–dryrun`, `–force`, `–debug` and `–warn` options to command line interface.
-
#options_help(parser, options) ⇒ Object
Add ‘–help` option to command line parser.
-
#options_url(parser, options) ⇒ Object
Add ‘–url` option to command line parser.
-
#parse(argv) ⇒ Hash
Parse controller options from command line arguments.
Instance Method Details
#call(*argv) ⇒ Object
Execute command.
18 19 20 21 22 23 24 25 26 |
# File 'lib/brite/command.rb', line 18 def call(*argv) = parse(argv) begin controller().build rescue => e $DEBUG ? raise(e) : puts(e.) end end |
#controller(options) ⇒ Controller
Create an instance of Brite::Controller given controller options.
33 34 35 |
# File 'lib/brite/command.rb', line 33 def controller() Controller.new() end |
#options_general(parser, options) ⇒ Object
Add ‘–trace`, `–dryrun`, `–force`, `–debug` and `–warn` options to command line interface. These are all “global” options which means they set global variables if used.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/brite/command.rb', line 87 def (parser, ) parser.on("--trace", "show extra operational information") do $TRACE = true end parser.on("--dryrun", "-n", "don't actually write to disk") do $DRYRUN = true end parser.on("--force", "force overwrites") do $FORCE = true end parser.on("--debug", "run in debug mode") do $DEBUG = true end parser.on("--warn", "show Ruby warnings") do $VERBOSE = true end end |
#options_help(parser, options) ⇒ Object
Add ‘–help` option to command line parser.
118 119 120 121 122 123 |
# File 'lib/brite/command.rb', line 118 def (parser, ) parser.on_tail("--help", "display this help message") do puts opt exit end end |
#options_url(parser, options) ⇒ Object
Add ‘–url` option to command line parser.
70 71 72 73 74 |
# File 'lib/brite/command.rb', line 70 def (parser, ) parser.on("--url URL", "website fully qualified URL") do |url| [:url] = url end end |
#parse(argv) ⇒ Hash
Parse controller options from command line arguments.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/brite/command.rb', line 42 def parse(argv) parser = OptionParser.new = { :output => nil, :url => nil } parser, parser, parser, parser.parse!(argv) [:location] = argv.shift || '.' end |