Class: VagrantPlugins::VagrantJson::Command::Init
- Inherits:
-
Object
- Object
- VagrantPlugins::VagrantJson::Command::Init
- Defined in:
- lib/vagrant-json/command/init.rb
Instance Method Summary collapse
- #create_default_yaml(box_name = nil, box_url = nil) ⇒ Object
- #create_directories ⇒ Object
- #create_vagrantfile ⇒ Object
- #create_vm_yaml(vm_name, box_name: "ubuntu/xenial64") ⇒ Object
- #execute ⇒ Object
Instance Method Details
#create_default_yaml(box_name = nil, box_url = nil) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/vagrant-json/command/init.rb', line 63 def create_default_yaml(box_name = nil, box_url = nil) save_path = @env.cwd.join("default.yml") raise Exception if save_path.exist? template_path = VagrantJson.source_root.join("templates/default.yml") contents = Vagrant::Util::TemplateRenderer.render(template_path, :box_name => box_name, :box_url => box_url) save_path.open("w+") do |f| f.write(contents) end end |
#create_directories ⇒ Object
59 60 61 |
# File 'lib/vagrant-json/command/init.rb', line 59 def create_directories Dir.mkdir(".vagrant_config") end |
#create_vagrantfile ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/vagrant-json/command/init.rb', line 48 def create_vagrantfile save_path = @env.cwd.join("Vagrantfile") raise Exception if save_path.exist? template_path = VagrantJson.source_root.join("templates/Vagrantfile") contents = Vagrant::Util::TemplateRenderer.render(template_path) save_path.open("w+") do |f| f.write(contents) end end |
#create_vm_yaml(vm_name, box_name: "ubuntu/xenial64") ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/vagrant-json/command/init.rb', line 76 def create_vm_yaml(vm_name, box_name: "ubuntu/xenial64") save_path = @env.cwd.join(".vagrant_config/#{vm_name}.yml") raise Exception if save_path.exist? template_path = VagrantJson.source_root.join("templates/local.yml") contents = Vagrant::Util::TemplateRenderer.render(template_path, :host_name => "#{vm_name}.vagrant.local", :box_name => box_name) save_path.open("w+") do |f| f.write(contents) end end |
#execute ⇒ Object
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/vagrant-json/command/init.rb', line 7 def execute = {} opts = OptionParser.new do |o| o.separator "Usage: vagrant json init [options] <name, url, or path>" o.separator "" o.separator "Options:" o.separator "" o.on("-f", "--force", "Overwrite existing yml and Vagrantfile") do |n| [:force] = n end o.on("-r", "--remove", "Remove existing yml and Vagrantfile") do |n| [:remove] = n end end argv = (opts) return if !argv # if argv.empty? || argv.length > 2 # raise Vagrant::Errors::CLIInvalidUsage, # help: opts.help.chomp # end create_vagrantfile create_directories create_vm_yaml("app01") create_vm_yaml("db01") create_default_yaml(argv[0], argv[1]) @env.ui.info(I18n.t( "vagrant.plugins.yml.commands.init.success", avail_dir: 'available.d', enabled_dir: 'enabled.d', local_dir: 'local.d' ), :prefix => false) # Success, exit status 0 0 end |