Class: Xnlogic::CLI

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

Defined Under Namespace

Classes: Application, Core, Deploy

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ CLI

Returns a new instance of CLI.



16
17
18
19
20
21
22
23
24
# File 'lib/xnlogic/cli.rb', line 16

def initialize(*args)
  super
rescue UnknownArgumentError => e
  raise InvalidOption, e.message
ensure
  self.options ||= {}
  Xnlogic.ui = UI::Shell.new(options)
  Xnlogic.ui.level = "debug" if options["verbose"]
end

Class Method Details

.handle_no_command_error(command, has_namespace = $thor_runner) ⇒ Object



53
54
55
56
# File 'lib/xnlogic/cli.rb', line 53

def self.handle_no_command_error(command, has_namespace = $thor_runner)
  return super unless command_path = Xnlogic.which("xnlogic-#{command}")
  Kernel.exec(command_path, *ARGV[1..-1])
end

.source_rootObject



153
154
155
# File 'lib/xnlogic/cli.rb', line 153

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

.startObject



9
10
11
12
13
14
# File 'lib/xnlogic/cli.rb', line 9

def self.start(*)
  super
rescue Exception => e
  Xnlogic.ui = UI::Shell.new
  raise e
end

.vm_config_optionsObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/xnlogic/cli.rb', line 59

def self.vm_config_options
  method_option "key", type: :string, banner:
    "You must supply an XN key to be able to download the proprietary dependencies needed to boot your application"
  method_option "cpus", type: :numeric, banner:
    "Number of Virtual CPUs the Development VM should use (default 2)"
  method_option "memory", type: :numeric, banner:
    "Amount of RAM to allow the Development VM to use (default 2048, in MB)"
  method_option "root", type: :string, banner:
    "Optionally specify a different root directory name"
  method_option "provision", type: :boolean, banner:
    "Update the VM with the new provisioning settings"
  method_option "up", type: :boolean, banner:
    "Start the the VM (will provision automatically only on the first run)"
end

Instance Method Details

#application(name = nil) ⇒ Object



84
85
86
87
88
89
90
91
92
# File 'lib/xnlogic/cli.rb', line 84

def application(name = nil)
  app = Application.new(options, self)
  if options['same'] or name.nil?
    app.in_existing_project
  else
    app.set_name(name)
  end
  app.application
end

#gem_sourcesObject



107
108
109
110
111
# File 'lib/xnlogic/cli.rb', line 107

def gem_sources
  app = Application.new(options, self).in_existing_project
  app.show_source "https://rubygems.org/"
  app.show_source "https://#{app.options['key']}@gems.xnlogic.com/"
end

#help(cli = nil) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/xnlogic/cli.rb', line 35

def help(cli = nil)
  case cli
  when nil       then command = "xnlogic"
  else                command = "xnlogic-#{cli}"
  end
  manpages = %w(xnlogic)
  if manpages.include?(command)
    root = File.expand_path("../man", __FILE__)
    if Xnlogic.which("man") && root !~ %r{^file:/.+!/META-INF/jruby.home/.+}
      Kernel.exec "man #{root}/#{command}"
    else
      puts File.read("#{root}/#{command}.txt")
    end
  else
    super
  end
end

#key(xn_key) ⇒ Object



129
130
131
132
# File 'lib/xnlogic/cli.rb', line 129

def key(xn_key)
  app = Application.new(options, self)
  app.update_key(xn_key)
end

#provisionObject



119
120
121
# File 'lib/xnlogic/cli.rb', line 119

def provision
  system 'vagrant provision'
end

#server_profile(hostname) ⇒ Object



142
143
144
145
# File 'lib/xnlogic/cli.rb', line 142

def server_profile(hostname)
  app = Deploy.new(options, self)
  app.server_profile(hostname)
end

#sshObject



124
125
126
# File 'lib/xnlogic/cli.rb', line 124

def ssh
  exec 'vagrant ssh'
end

#upObject



114
115
116
# File 'lib/xnlogic/cli.rb', line 114

def up
  system 'vagrant up'
end

#versionObject



148
149
150
# File 'lib/xnlogic/cli.rb', line 148

def version
  puts(Xnlogic::VERSION)
end

#vm_configObject



98
99
100
# File 'lib/xnlogic/cli.rb', line 98

def vm_config
  Application.new(options, self).in_existing_project.vm_config
end