Class: Skynet::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/skynet/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



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

def self.source_root
  File.join File.dirname(__FILE__), 'templates'
end

Instance Method Details

#build(project = nil, branch = nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/skynet/cli.rb', line 51

def build(project=nil, branch=nil)
  all_apps = load_configuration options[:file]

  if project.nil?
    all_apps.each do |app, config|
      begin
        Builder.build app, config
      rescue ArgumentError
        next
      end
    end
  else
    config = all_apps[project]
    if config.nil?
      Skynet.logger.error "Could not find configuration for #{project}"
    else
      Builder.build project, config, branch
    end
  end
end

#checkObject



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/skynet/cli.rb', line 74

def check
  all_apps = load_configuration options[:file]
  all_apps.each do |app, config|
    builder = Builder.for_app app, config
    if builder.valid?
      puts "#{app} configuration is valid"
    else
      puts "#{app} configuration errors: #{builder.errors.full_messages.join '. '}"
    end
  end
end

#configObject



95
96
97
98
# File 'lib/skynet/cli.rb', line 95

def config
  copy_file 'config.yml', options[:file] unless File.exist? options[:file]
  run_wizard options[:file]
end

#hook(project) ⇒ Object



104
105
106
107
108
109
110
111
112
# File 'lib/skynet/cli.rb', line 104

def hook(project)
  if File.exist? options[:output]
    Skynet.logger.fatal %{Output file "#{options[:output]}" already exists}
    exit 1
  end
  config = load_configuration(options[:file])[project]
  server = "#{options[:server].chomp '/'}/#{project}"
  HookGenerator.new(config, server, options[:output]).generate
end

#installObject



88
89
90
91
# File 'lib/skynet/cli.rb', line 88

def install
  copy_file 'config.yml'
  run_wizard if options[:wizard]
end

#serverObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/skynet/cli.rb', line 24

def server
  Skynet.logger = Logger.new(options[:log], 'weekly') unless options[:log].nil?

  unless File.exist? options[:file]
    Skynet.logger.fatal "Configuration file #{options[:file]} cannot be found"
    raise ArgumentError.new "Cannot find configuration file"
  end

  Skynet::App.configure do |app|
    app.set :config, load_configuration(options[:file])
  end

  server = Thin::Server.new(options[:host], options[:port]) do
    run Skynet::App
  end

  begin
    server.start!
  rescue => ex
    Skynet.logger.fatal ex.message
    Skynet.logger.fatal ex.backtrace.join("\n")
    raise ex
  end
end

#versionObject



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

def version
  puts "Skynet #{Skynet::VERSION}"
end