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"
Instance Attribute Summary collapse
-
#env ⇒ Object
Returns the value of attribute env.
-
#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
- #demo_files ⇒ Object
- #demos ⇒ Object
-
#execute ⇒ Object
Run demonstrations.
-
#initialize ⇒ Command
constructor
A new instance of Command.
-
#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_environment ⇒ Object
Require requirement file (from -e option..
-
#require_libraries ⇒ Object
Require libraries (from -r option).
-
#runner ⇒ Object
Instance of Runner class.
Constructor Details
#initialize ⇒ Command
Returns a new instance of Command.
57 58 59 60 61 62 63 64 65 |
# File 'lib/qed/command.rb', line 57 def initialize @format = nil @env = nil @profile = nil @requires = [] @loadpath = [] @files = [] @options = {} end |
Instance Attribute Details
#env ⇒ Object
Returns the value of attribute env.
53 54 55 |
# File 'lib/qed/command.rb', line 53 def env @env end |
#files ⇒ Object
Files to be run.
39 40 41 |
# File 'lib/qed/command.rb', line 39 def files @files end |
#format ⇒ Object
Ouput format.
22 23 24 |
# File 'lib/qed/command.rb', line 22 def format @format end |
#loadpath ⇒ Object
Returns the value of attribute loadpath.
47 48 49 |
# File 'lib/qed/command.rb', line 47 def loadpath @loadpath end |
#options ⇒ Object (readonly)
Command-line options.
36 37 38 |
# File 'lib/qed/command.rb', line 36 def @options end |
#profile ⇒ Object (readonly)
Options defined by selected profile.
33 34 35 |
# File 'lib/qed/command.rb', line 33 def profile @profile end |
#requires ⇒ Object
Returns the value of attribute requires.
50 51 52 |
# File 'lib/qed/command.rb', line 50 def requires @requires end |
#trace ⇒ Object (readonly)
Trace execution?
30 31 32 |
# File 'lib/qed/command.rb', line 30 def trace @trace end |
Class Method Details
.execute ⇒ Object
Initialize and execute.
17 18 19 |
# File 'lib/qed/command.rb', line 17 def self.execute new.execute end |
Instance Method Details
#demo_files ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/qed/command.rb', line 152 def demo_files files = self.files #if files.empty? # if File.directory?('test') # files << 'test/doc{,s}' # files << 'test/demo{,s}' # end #end files = files.map do |pattern| Dir[pattern] end.flatten.uniq files = files.map do |file| if File.directory?(file) Dir[File.join(file,'**','*{.qed,.rd,.rdoc,.md,.markdown}')] else file end end files = files.flatten.uniq #files = files.select do |file| # %w{.yml .yaml .rb}.include?(File.extname(file)) #end files end |
#demos ⇒ Object
146 147 148 |
# File 'lib/qed/command.rb', line 146 def demos demo_files end |
#execute ⇒ Object
Run demonstrations.
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/qed/command.rb', line 211 def execute parse abort "No documents." if demos.empty? prepare_loadpath require_libraries require_environment # TODO: Remove case, can :script be done with Reporter or do we ne need selectable Runner? case format when :script demos.each do |spec| puts spec.to_script end else runner.check end end |
#opts ⇒ Object
Instance of OptionParser
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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/qed/command.rb', line 69 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 Options (pick one):") opt.on('--dotprogress', '-d', "use dot-progress reporter [default]") do @options[:format] = :summary end opt.on('--verbatim', '-v', "use verbatim reporter") do @options[:format] = :verbatim end opt.on('--summary', '-s', "use summary reporter") do @options[:format] = :summary end opt.on('--script', "psuedo-reporter") do @options[:script] # psuedo-reporter end opt.separator("Control Options:") opt.on('--env', '-e [NAME]', "runtime environment [default]") do |name| @options[:env] = 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.
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/qed/command.rb', line 191 def parse @files = [] argv = ARGV.dup opts.parse!(argv) @files.concat(argv) if profile args = profiles[profile] argv = Shellwords.shellwords(args) opts.parse!(argv) @files.concat(argv) end .each do |k,v| __send__("#{k}=", v) end end |
#prepare_loadpath ⇒ Object
Add to load path (from -I option).
243 244 245 |
# File 'lib/qed/command.rb', line 243 def prepare_loadpath loadpath.each{ |dir| $LOAD_PATH.unshift(dir) } end |
#profiles ⇒ Object
Profile configurations.
234 235 236 237 238 239 |
# File 'lib/qed/command.rb', line 234 def profiles @profiles ||= ( file = Dir["#{CONFDIR}/profile{,s}.{yml,yaml}"].first file ? YAML.load(File.new(file)) : {} ) end |
#require_environment ⇒ Object
Require requirement file (from -e option.
255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/qed/command.rb', line 255 def require_environment if env if file = Dir["#{CONFDIR}/{env,environments}/#{env}.rb"].first require(file) end else if file = Dir["#{CONFDIR}/env.rb"].first require(file) elsif file = Dir["#{CONFDIR}/{env,environments}/default.rb"].first require(file) end end end |
#require_libraries ⇒ Object
Require libraries (from -r option).
249 250 251 |
# File 'lib/qed/command.rb', line 249 def require_libraries requires.each{ |file| require(file) } end |