Top Level Namespace

Includes:
Contracts

Defined Under Namespace

Modules: Os, Recipe, Specs

Constant Summary collapse

SPECS_VERSION_STRING =
"specs #{Specs::VERSION}"
SPECS_HOME_PAGE =
'https://github.com/mcandre/specs#readme'
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)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.check_ruby_versionObject



260
261
262
263
264
265
266
# File 'lib/specs.rb', line 260

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



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/specs.rb', line 212

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

.run(cmd, aspect) ⇒ Object

Print a command line instruction and its output, Emulating a user manually entering the instruction.



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/specs.rb', line 238

def self.run(cmd, aspect)
  # Newline to visually separate multiple aspect commands.
  puts ''

  if !cmd
    puts "#{aspect} aspect not implemented for this system"
  elsif cmd == SPECS_VERSION_STRING
    puts 'specs --version'
    puts SPECS_VERSION_STRING
  else
    puts cmd

    output = `#{cmd} 2>&1`

    if output.include?(Recipe.command_not_found)
      puts "#{cmd.split.first} not found"
    else
      puts output
    end
  end
end

.usageObject



268
269
270
271
272
# File 'lib/specs.rb', line 268

def self.usage
  puts "Specs:\n\n#{SPECS_VERSION_STRING}\n#{SPECS_HOME_PAGE}"

  exit if ARGV.include?('--version')
end

Instance Method Details

#mainObject



274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# File 'lib/specs.rb', line 274

def main
  check_ruby_version

  usage

  # Default aspects
  aspects = %w(os) # hardware)

  aspects = ARGV unless ARGV.empty?

  aspects -= ['specs', '-v', 'version', '-version', '--version']

  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
end