Class: Xnlogic::CLI::Application
- Defined in:
- lib/xnlogic/cli/application.rb
Instance Attribute Summary collapse
-
#app_name ⇒ Object
readonly
Returns the value of attribute app_name.
-
#base_name ⇒ Object
readonly
Returns the value of attribute base_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Attributes inherited from Core
#app, #ignore_options, #options, #thor
Instance Method Summary collapse
- #application ⇒ Object
- #generate_application ⇒ Object
- #generate_vm_config ⇒ Object
- #in_existing_project ⇒ Object
-
#initialize(options, thor) ⇒ Application
constructor
A new instance of Application.
- #install_vagrant_note ⇒ Object
- #options_file ⇒ Object
- #options_filename ⇒ Object
- #require_key ⇒ Object
- #set_name(app_name) ⇒ Object
- #show_source(source) ⇒ Object
- #template_options ⇒ Object
- #vm_config ⇒ Object
Methods inherited from Core
Constructor Details
#initialize(options, thor) ⇒ Application
Returns a new instance of Application.
7 8 9 10 |
# File 'lib/xnlogic/cli/application.rb', line 7 def initialize(, thor) super @ignore_options = ['up', 'provision'] end |
Instance Attribute Details
#app_name ⇒ Object (readonly)
Returns the value of attribute app_name.
5 6 7 |
# File 'lib/xnlogic/cli/application.rb', line 5 def app_name @app_name end |
#base_name ⇒ Object (readonly)
Returns the value of attribute base_name.
5 6 7 |
# File 'lib/xnlogic/cli/application.rb', line 5 def base_name @base_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/xnlogic/cli/application.rb', line 5 def name @name end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
5 6 7 |
# File 'lib/xnlogic/cli/application.rb', line 5 def root @root end |
Instance Method Details
#application ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/xnlogic/cli/application.rb', line 58 def application require_key generate_vm_config if ['vm_config'] generate_application Xnlogic.ui.info "Initializing git repo in #{app}" Dir.chdir(app) { system 'git init' and system 'git add .' } install_vagrant_note if ['up'] Dir.chdir(app) { system 'vagrant up' } else Xnlogic.ui.info "" Xnlogic.ui.info "To start your VM, run the following:" Xnlogic.ui.info "" Xnlogic.ui.info "cd #{root}" Xnlogic.ui.info "xnlogic up" end if ['provision'] Dir.chdir(app) { system 'vagrant provision' } end Xnlogic.ui.info "To begin working with your VM, ssh into it with the following command:" Xnlogic.ui.info "" Xnlogic.ui.info "xnlogic ssh" Xnlogic.ui.info "" Xnlogic.ui.info "Once logged in to the server, try the xn-console and xn-server commands" end |
#generate_application ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/xnlogic/cli/application.rb', line 151 def generate_application opts = namespaced_path = opts[:namespaced_path] templates = { "gitignore.tt" => ".gitignore", ".rspec.tt" => ".rspec", "gemspec.tt" => "#{namespaced_path}.gemspec", "Rakefile.tt" => "Rakefile", "Readme.md.tt" => "Readme.md", "config.ru.tt" => "config.ru", "dev/console.rb.tt" => "dev/console.rb", "tasks/deploy.rb.tt" => "tasks/deploy.rb", "torquebox.yml.tt" => "torquebox.yml", "torquebox_init.rb.tt" => "torquebox_init.rb", "lib/gemname.rb.tt" => "lib/#{namespaced_path}.rb", "lib/gemname/version.rb.tt" => "lib/#{namespaced_path}/version.rb", "lib/gemname/initializers/inflections.rb.tt" => "lib/#{namespaced_path}/initializers/inflections.rb", "lib/gemname/parts/has_notes.rb.tt" => "lib/#{namespaced_path}/parts/has_notes.rb", "lib/gemname/parts/note.rb.tt" => "lib/#{namespaced_path}/parts/note.rb", "lib/gemname/type/url.rb.tt" => "lib/#{namespaced_path}/type/url.rb", "lib/gemname/fixtures.rb.tt" => "lib/#{namespaced_path}/fixtures.rb", "lib/gemname/models.rb.tt" => "lib/#{namespaced_path}/models.rb", "lib/gemname/permissions.rb.tt" => "lib/#{namespaced_path}/permissions.rb", "lib/gemname/type.rb.tt" => "lib/#{namespaced_path}/type.rb", "lib/fixtures/sample_fixtures.rb.tt" => "lib/fixtures/sample_fixtures.rb", "spec/spec_helper.rb.tt" => "spec/spec_helper.rb", "spec/gemname/gemname_spec.rb.tt" => "spec/#{namespaced_path}/#{name}_spec.rb", } Xnlogic.ui.info "" Xnlogic.ui.info "Creating application templates" Xnlogic.ui.info "" templates.each do |src, dst| thor.template("application/#{src}", app.join(dst), opts) end end |
#generate_vm_config ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/xnlogic/cli/application.rb', line 133 def generate_vm_config opts = base_templates = { "Vagrantfile.tt" => "Vagrantfile", "Gemfile.tt" => "Gemfile", "config/vagrant.provision.tt" => "config/vagrant.provision", "config/datomic.conf" => "config/datomic.conf", "config/transactor.properties" => "config/transactor.properties", } Xnlogic.ui.info "" Xnlogic.ui.info "Creating Vagrant configuration" Xnlogic.ui.info "" base_templates.each do |src, dst| thor.template("vagrant/#{src}", app.join(dst), opts) end end |
#in_existing_project ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/xnlogic/cli/application.rb', line 32 def in_existing_project @root = .fetch('root', '.') @app = Pathname.pwd.join(root) super() @name ||= ['name'] self end |
#install_vagrant_note ⇒ Object
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/xnlogic/cli/application.rb', line 105 def install_vagrant_note ver = `vagrant --version` rescue '' if ver == '' Xnlogic.ui.info "" Xnlogic.ui.info "Please ensure that the following dependencies are installed on your computer" Xnlogic.ui.info "to continue." Xnlogic.ui.info " - Vagrant: https://www.vagrantup.com/" Xnlogic.ui.info " - VirtualBox: https://www.virtualbox.org/wiki/Downloads" end end |
#options_file ⇒ Object
28 29 30 |
# File 'lib/xnlogic/cli/application.rb', line 28 def app + end |
#options_filename ⇒ Object
24 25 26 |
# File 'lib/xnlogic/cli/application.rb', line 24 def 'config/app_options.yaml' end |
#require_key ⇒ Object
51 52 53 54 55 56 |
# File 'lib/xnlogic/cli/application.rb', line 51 def require_key unless ['key'] Xnlogic.ui.info 'You must specify a --key option to generate an application.' exit 1 end end |
#set_name(app_name) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/xnlogic/cli/application.rb', line 12 def set_name(app_name) if File.exists?() Xnlogic.ui.info "Can not create an application within an application." exit 1 end @name = app_name.chomp("/").tr('-', '_') # remove trailing slash if present @root = .fetch('root', @name) @app = Pathname.pwd.join(root) ['name'] = @name self end |
#show_source(source) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/xnlogic/cli/application.rb', line 40 def show_source(source) case ['format'] when 'bundler' Xnlogic.ui.info "source \"#{source}\"" when 'rubygems' Xnlogic.ui.info "gem sources -a #{source}" else Xnlogic.ui.info source end end |
#template_options ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/xnlogic/cli/application.rb', line 116 def namespaced_path = name constant_name = namespaced_path.split('_').map{|p| p[0..0].upcase + p[1..-1] }.join git_user_name = `git config user.name`.chomp git_user_email = `git config user.email`.chomp { :name => name, :namespaced_path => namespaced_path, :constant_name => constant_name, :author => git_user_name.empty? ? "TODO: Write your name" : git_user_name, :email => git_user_email.empty? ? "TODO: Write your email address" : git_user_email, :vm_cpus => ['cpus'], :vm_memory => ['memory'], :xn_key => ['key'], } end |
#vm_config ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/xnlogic/cli/application.rb', line 88 def vm_config generate_vm_config install_vagrant_note if ['provision'] or ['up'] Dir.chdir(app) { system 'vagrant up' } if ['up'] Dir.chdir(app) { system 'vagrant provision' } if ['provision'] else Xnlogic.ui.info "" Xnlogic.ui.info "If you have an existing VM that you are updating, run 'xnlogic provision'," Xnlogic.ui.info "otherwise, run 'xnlogic up'" Xnlogic.ui.info "" end Xnlogic.ui.info "Once that is done, run 'xnlogic ssh' to log in to the VM." end |