Module: Specs
- Includes:
- Contracts::Modules
- Defined in:
- lib/version.rb,
lib/cli.rb,
lib/specs.rb
Overview
Specs
Constant Summary collapse
- SPECS_DIR =
Pathname.new(File.dirname(__FILE__))
- BUILTINS =
%w(specs os arch ruby)
- SEP =
File::SEPARATOR
- RECIPE_DIR =
…/specs/aspects
[SPECS_DIR, 'aspects'].join(SEP)
- VERSION =
'0.21'
Class Method Summary collapse
- .check_ruby_version ⇒ Object
- .command(aspect) ⇒ Object
- .main ⇒ Object
-
.run(cmd, aspect) ⇒ Object
Print a command line instruction and its output, Emulating a user manually entering the instruction.
Class Method Details
.check_ruby_version ⇒ Object
251 252 253 254 255 256 257 |
# File 'lib/specs.rb', line 251 def self.check_ruby_version if Recipe.ruby1_8? puts 'Requires Ruby 1.9 or higher.' puts 'http://www.ruby-lang.org/' exit end end |
.command(aspect) ⇒ Object
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/specs.rb', line 203 def self.command(aspect) # Ruby methods can't use hyphens (-), # So translate to underscores (_) # When looking up known aspects. method = aspect.gsub('-', '_').to_sym # Package? if aspect.include?(':') package_manager, package = aspect.split(':') package_manager = package_manager.to_sym if Recipe::Package.methods.include?(package_manager) Recipe::Package.send(package_manager, package) end # Known aspect? elsif Recipe.methods.include?(method) Recipe.send(method) # Unknown aspect. # Default to --version flag. else "#{aspect} --version" end end |
.main ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/cli.rb', line 18 def self.main check_ruby_version begin = Docopt::docopt(USAGE, version: Specs::VERSION) aspects = ['<aspect>'] # Work around https://github.com/docopt/docopt/issues/274 if aspects == [] aspects = ['os', 'hardware'] end # Print specs' own version, and filter out redundant requests aspects = ['specs'] + (aspects - ['specs']) aspects.each do |aspect| # What does the aspect module say to run # in order to retrieve the aspect information? cmds = command(aspect) if !cmds || cmds.instance_of?(String) run(cmds, aspect) # Module returns an array of command strings. elsif cmds.instance_of?(Array) cmds.each { |cmd| run(cmd, aspect) } end end rescue Docopt::Exit => e puts e. end rescue Interrupt nil end |
.run(cmd, aspect) ⇒ Object
Print a command line instruction and its output, Emulating a user manually entering the instruction.
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/specs.rb', line 229 def self.run(cmd, aspect) if !cmd puts "#{aspect} aspect not implemented for this system" elsif cmd == 'specs' puts 'specs --version' puts Specs::Version else puts cmd output = SystemWithAliases::execute(cmd) if output.include?(Recipe.command_not_found) puts "#{cmd.split.first} not found" else puts output end # Vertically separate multiple aspects puts '' end end |