Module: Boot

Defined in:
lib/boot.rb,
lib/Boot/Lib/autoload.rb

Defined Under Namespace

Modules: Lib

Constant Summary collapse

VERSION =
"1.0.0"
LIB_PATH =
File.dirname(File.dirname(File.expand_path("../", __FILE__)))

Class Method Summary collapse

Class Method Details

.configObject



52
53
54
# File 'lib/boot.rb', line 52

def self.config
  return @config
end

.dirObject



48
49
50
# File 'lib/boot.rb', line 48

def self.dir
  File.dirname(File.expand_path(__FILE__))
end

.mainObject



7
8
9
10
11
12
13
14
15
16
17
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
# File 'lib/boot.rb', line 7

def self.main
  # Open and parse default config
  default_config_file_path = File.dirname(__FILE__) + '/boot-default-config.json'
  default_config_object = JSON.parse(File.open(default_config_file_path, "rb").read)
  
  # Open and barse .boot file
  dot_config_file_path = File.expand_path('~/.boot')
  dot_config_object = {}
  if (File.exists?(dot_config_file_path))
    dot_config_file = File.open(dot_config_file_path, "rb")
    dot_config_object = JSON.parse(dot_config_file.read)
  end

  # Merge default and .boot
  config_object = default_config_object.merge(dot_config_object)

  begin
    @config = Boot::Lib::Core::Config.new(config_object)
  rescue Boot::Lib::Core::InvalidConfigException => e
    puts e.message
    exit
  end

  @sub_commands = {}
  @sub_commands['help'] = Boot::Lib::Commands::Help
  @sub_commands['new']  = Boot::Lib::Commands::New
  @sub_commands['config']  = Boot::Lib::Commands::Config
  @sub_commands['version']  = Boot::Lib::Commands::Version
  @sub_commands['template']  = Boot::Lib::Commands::Template

  if ARGV[0] == nil
    Boot::Lib::Commands::Help.run([]);
  elsif @sub_commands[ARGV[0]].nil?
    puts "'#{ARGV[0]}' is not a sub command. See 'boot help'"
  else
    subCmdObj = @sub_commands[ARGV[0].downcase]
    ARGV.shift; # Remove subcommand from ARGV, rest is options
    subCmdObj.run(ARGV)
  end
end

.sub_commandsObject

attr_reader :sub_commands



57
58
59
# File 'lib/boot.rb', line 57

def self.sub_commands
  return @sub_commands
end