Class: QED::Command
- Inherits:
-
Object
- Object
- QED::Command
- Defined in:
- lib/qed/command.rb
Overview
QED Commandline Tool
Constant Summary collapse
- CONFDIR =
Configuration directory.
"{.,}config/qed"
- DEFAULT_DEMO_LOCATION =
Default location of demonstrations if no specific files or locations given. This is use in Dir.glob.
'{demo,demos}'
Instance Attribute Summary collapse
-
#extension ⇒ Object
Returns the value of attribute extension.
-
#files ⇒ Object
Files to be run.
-
#format ⇒ Object
Ouput format.
-
#loadpath ⇒ Object
Returns the value of attribute loadpath.
-
#options ⇒ Object
readonly
Command-line options.
-
#profile ⇒ Object
readonly
Options defined by selected profile.
-
#requires ⇒ Object
Returns the value of attribute requires.
-
#trace ⇒ Object
readonly
Trace execution?.
Class Method Summary collapse
-
.execute ⇒ Object
Initialize and execute.
Instance Method Summary collapse
- #demos ⇒ Object
-
#execute ⇒ Object
Run demonstrations.
-
#initialize ⇒ Command
constructor
TODO: Should extension and profile have a common reference?.
-
#opts ⇒ Object
Instance of OptionParser.
-
#parse ⇒ Object
Parse command-line options along with profile options.
-
#prepare_loadpath ⇒ Object
Add to load path (from -I option).
-
#profiles ⇒ Object
Profile configurations.
-
#require_libraries ⇒ Object
Require libraries (from -r option).
-
#require_profile ⇒ Object
Require requirement file (from -e option).
- #root ⇒ Object
-
#session ⇒ Object
Session instance.
Constructor Details
#initialize ⇒ Command
TODO: Should extension and profile have a common reference?
62 63 64 65 66 67 68 69 70 |
# File 'lib/qed/command.rb', line 62 def initialize @format = :dotprogress @extension = :default @profile = :default @requires = [] @loadpath = [] @files = [] @options = {} end |
Instance Attribute Details
#extension ⇒ Object
Returns the value of attribute extension.
58 59 60 |
# File 'lib/qed/command.rb', line 58 def extension @extension end |
#files ⇒ Object
Files to be run.
44 45 46 |
# File 'lib/qed/command.rb', line 44 def files @files end |
#format ⇒ Object
Ouput format.
27 28 29 |
# File 'lib/qed/command.rb', line 27 def format @format end |
#loadpath ⇒ Object
Returns the value of attribute loadpath.
52 53 54 |
# File 'lib/qed/command.rb', line 52 def loadpath @loadpath end |
#options ⇒ Object (readonly)
Command-line options.
41 42 43 |
# File 'lib/qed/command.rb', line 41 def @options end |
#profile ⇒ Object (readonly)
Options defined by selected profile.
38 39 40 |
# File 'lib/qed/command.rb', line 38 def profile @profile end |
#requires ⇒ Object
Returns the value of attribute requires.
55 56 57 |
# File 'lib/qed/command.rb', line 55 def requires @requires end |
#trace ⇒ Object (readonly)
Trace execution?
35 36 37 |
# File 'lib/qed/command.rb', line 35 def trace @trace end |
Class Method Details
.execute ⇒ Object
Initialize and execute.
22 23 24 |
# File 'lib/qed/command.rb', line 22 def self.execute new.execute end |
Instance Method Details
#demos ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/qed/command.rb', line 158 def demos files = self.files types = %w{qed rdoc md markdown} #Tilt.mappings.keys if files.empty? files << DEFAULT_DEMO_LOCATION end files = files.map do |pattern| Dir[pattern] end.flatten.uniq files = files.map do |file| if File.directory?(file) Dir[File.join(file,'**','*.{' + types.join(',') + '}')] else file end end files = files.flatten.uniq.sort #files = files.select do |file| # %w{.yml .yaml .rb}.include?(File.extname(file)) #end files end |
#execute ⇒ Object
Run demonstrations.
210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/qed/command.rb', line 210 def execute parse abort "No documents." if demos.empty? prepare_loadpath require_libraries require_profile session.run end |
#opts ⇒ Object
Instance of OptionParser
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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/qed/command.rb', line 74 def opts @opts ||= OptionParser.new do |opt| opt.separator("Custom Profiles:") unless profiles.empty? profiles.each do |name, value| o = "--#{name}" opt.on(o, "#{name} custom profile") do @profile = name end end opt.separator("Report Formats (pick one):") opt.on('--dotprogress', '-d', "use dot-progress reporter [default]") do @options[:format] = :dotprogress end opt.on('--verbatim', '-v', "use verbatim reporter") do @options[:format] = :verbatim end opt.on('--bullet', '-b', "use bullet-point reporter") do @options[:format] = :bullet end opt.on('--html', '-h', "use underlying HTML reporter") do @options[:format] = :html end opt.on('--format', '-f FORMAT', "use custom reporter") do |format| @options[:format] = format end #opt.on('--script', "psuedo-reporter") do # @options[:format] = :script # psuedo-reporter #end opt.separator("Control Options:") opt.on('--ext', '-e [NAME]', "runtime extension [default]") do |name| @options[:extension] = name end opt.on('--loadpath', "-I PATH", "add paths to $LOAD_PATH") do |arg| @options[:loadpath] ||= [] @options[:loadpath].concat(arg.split(/[:;]/).map{ |dir| File.(dir) }) end opt.on('--require', "-r", "require library") do |arg| @options[:requires] ||= [] @options[:requires].concat(arg.split(/[:;]/)) #.map{ |dir| File.expand_path(dir) }) end opt.on('--trace', '-t', "show full backtraces for exceptions") do @options[:trace] = true end opt.on('--debug', "exit immediately upon raised exception") do $VERBOSE = true # wish this were called $WARN $DEBUG = true end opt.separator("Optional Commands:") opt.on_tail('--version', "display version") do puts "QED #{VERSION}" exit end opt.on_tail('--copyright', "display copyrights") do puts "Copyright (c) 2008, 2009 Thomas Sawyer, GPL License" exit end opt.on_tail('--help', '-h', "display this help message") do puts opt exit end end end |
#parse ⇒ Object
Parse command-line options along with profile options.
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/qed/command.rb', line 189 def parse @files = [] argv = ARGV.dup opts.parse!(argv) @files.concat(argv) #if profile if args = profiles[profile] argv = Shellwords.shellwords(args) opts.parse!(argv) @files.concat(argv) end #end .each do |k,v| __send__("#{k}=", v) end end |
#prepare_loadpath ⇒ Object
Add to load path (from -I option).
234 235 236 |
# File 'lib/qed/command.rb', line 234 def prepare_loadpath loadpath.each{ |dir| $LOAD_PATH.unshift(dir) } end |
#profiles ⇒ Object
Profile configurations.
225 226 227 228 229 230 |
# File 'lib/qed/command.rb', line 225 def profiles @profiles ||= ( file = Dir["#{CONFDIR}/profile{,s}.{yml,yaml}"].first file ? YAML.load(File.new(file)) : {} ) end |
#require_libraries ⇒ Object
Require libraries (from -r option).
240 241 242 |
# File 'lib/qed/command.rb', line 240 def require_libraries requires.each{ |file| require(file) } end |
#require_profile ⇒ Object
Require requirement file (from -e option).
246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/qed/command.rb', line 246 def require_profile return unless root # common environment, always loaded if present. #if file = Dir["#{root}/#{CONFDIR}/default.rb"].first # require(file) #end #env = env() || 'default' if file = Dir["#{root}/#{CONFDIR}/#{extension}.rb"].first require(file) end end |