// destroy func destroy(ccmd *cobra.Command, args []string) { // PreRun: runnable // if the command is being run with --remove-entry, it means an entry needs // to be removed from the hosts file and execution yielded back to the parent if removeEntry { hosts.RemoveDomain() os.Exit(0) // this exits the sudoed (child) destroy, not the parent proccess } // destroy the vm; this needs to happen before cleaning up the app to ensure // there is a Vagrantfile to run the command with (otherwise it will just get // re-created) fmt.Printf(stylish.Bullet("Destroying nanobox...")) fmt.Printf(stylish.Bullet("Nanobox may require admin privileges to modify your /etc/hosts and /etc/exports files.")) if err := vagrant.Destroy(); err != nil { // dont care if the project no longer exists... thats what we're doing anyway if err != err.(*os.PathError) { vagrant.Fatal("[commands/destroy] vagrant.Destroy() failed", err.Error()) } } // remove app; this needs to happen after the VM is destroyed so that the app // isn't just created again upon running the vagrant command fmt.Printf(stylish.Bullet("Deleting nanobox files (%s)", config.AppDir)) if err := os.RemoveAll(config.AppDir); err != nil { config.Fatal("[commands/destroy] os.RemoveAll() failed", err.Error()) } // attempt to remove the entry regardless of whether its there or not util.PrivilegeExec("dev destroy --remove-entry", fmt.Sprintf("Removing %s domain from /etc/hosts", config.Nanofile.Domain)) }
// // create func create(ccmd *cobra.Command, args []string) { // PreRun: initialize // if the command is being run with the "add" flag, it means an entry needs to // be added to the hosts file and execution yielded back to the parent if addEntry { hosts.AddDomain() os.Exit(0) // this exits the sudoed (child) created, not the parent proccess } // boot the vm fmt.Printf(stylish.Bullet("Creating a nanobox")) fmt.Printf(stylish.Bullet("Nanobox may require admin privileges to modify your /etc/hosts and /etc/exports files.")) if err := vagrant.Up(); err != nil { vagrant.Fatal("[commands/create] vagrant.Up() failed", err.Error()) } // after the machine boots, update the docker images updateImages(nil, args) // add the entry if needed if !hosts.HasDomain() { util.PrivilegeExec("dev create --add-entry", fmt.Sprintf("Adding %v domain to hosts file", config.Nanofile.Domain)) } // if devmode is detected, the machine needs to be rebooted for devmode to take // effect if config.Devmode { fmt.Printf(stylish.Bullet("Rebooting machine to finalize 'devmode' configuration...")) reload(nil, args) } }