Module: Prigner::CLI

Defined in:
lib/prigner/cli.rb

Overview

Command-Line Interface

This module look a command placed in CLI directory and run it.

Defined Under Namespace

Classes: Status

Class Method Summary collapse

Class Method Details

.commandsObject

List of commands placed in lib/prigner/cli/.



27
28
29
30
31
# File 'lib/prigner/cli.rb', line 27

def self.commands
  Dir["#{path}/*.rb"].map do |source|
    File.basename(source, ".rb")
  end.sort
end

.pathObject

The CLI path.



15
16
17
# File 'lib/prigner/cli.rb', line 15

def self.path
  "#{Prigner::ROOT}/lib/prigner/cli"
end

.rubyObject

Ruby VM installed in OS.



9
10
11
12
# File 'lib/prigner/cli.rb', line 9

def self.ruby
  File.join(*::RbConfig::CONFIG.values_at("bindir", "ruby_install_name")) +
  ::RbConfig::CONFIG["EXEEXT"]
end

.run(*args) ⇒ Object

Look command in CLI directory and execute (by exec).

Raises:

  • (RuntimeError)


39
40
41
42
43
44
# File 'lib/prigner/cli.rb', line 39

def self.run(*args)
  command = args.shift if commands.include? args.first
  raise RuntimeError, "unknown command '#{args.first}'" unless command
  rubyopt = "-I#{Prigner::ROOT}/lib"
  exec ruby, rubyopt, source(command), *args
end

.source(command) ⇒ Object

Source command placed in CLI directory.



34
35
36
# File 'lib/prigner/cli.rb', line 34

def self.source(command)
  "#{path}/#{command}.rb"
end

.templatesObject

List all templates as commands.



20
21
22
23
24
# File 'lib/prigner/cli.rb', line 20

def self.templates
  Prigner::Template.all.map do |namespace, templates|
    templates.map{ |template, custom| template.mask }
  end.flatten
end