cmd

package
v0.9.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2017 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigCommand = &cobra.Command{
	Use:   "config [provider]",
	Short: "Create or modify a ddev application config in the current directory",
	Run: func(cmd *cobra.Command, args []string) {

		appRoot, err := os.Getwd()
		if err != nil {
			util.Failed("Could not determine current working directory: %v\n", err)

		}

		provider := ddevapp.DefaultProviderName

		if len(args) > 1 {
			log.Fatal("Invalid argument detected. Please use 'ddev config' or 'ddev config [provider]' to configure a site.")
		}

		if len(args) == 1 {
			provider = args[0]
		}

		c, err := ddevapp.NewConfig(appRoot, provider)
		if err != nil {

			if c.ConfigExists() {
				util.Failed("Could not read config: %v", err)
			}
		}

		c.Provider = provider

		err = c.Config()
		if err != nil {
			util.Failed("There was a problem configuring your application: %v\n", err)
		}

		err = c.Write()
		if err != nil {
			util.Failed("Could not write ddev config file: %v\n", err)

		}

		if provider != "" {
			util.Success("Configuration complete. You may now run `ddev start` or `ddev pull`")
		}
		util.Success("Initial configuration file written successfully. See the configuration file for additional configuration options.")
	},
}

ConfigCommand represents the `ddev config` command

View Source
var DescribeCommand = &cobra.Command{
	Use:   "describe [sitename]",
	Short: "Get a detailed description of a running ddev site.",
	Long: `Get a detailed description of a running ddev site. Describe provides basic
information about a ddev site, including its name, location, url, and status.
It also provides details for MySQL connections, and connection information for
additional services like MailHog and phpMyAdmin. You can run 'ddev describe' from
a site directory to stop that site, or you can specify a site to describe by
running 'ddev stop <sitename>.`,
	Run: func(cmd *cobra.Command, args []string) {
		var siteName string

		if len(args) > 1 {
			util.Failed("Too many arguments provided. Please use `ddev describe` or `ddev describe [appname]`")
		}

		if len(args) == 1 {
			siteName = args[0]
		}

		out, err := describeApp(siteName)
		if err != nil {
			util.Failed("Could not describe app: %v", err)
		}
		fmt.Println(out)
	},
}

DescribeCommand represents the `ddev config` command

View Source
var DevListCmd = &cobra.Command{
	Use:   "list",
	Short: "List applications that exist locally",
	Long:  `List applications that exist locally.`,
	Run: func(cmd *cobra.Command, args []string) {
		apps := platform.GetApps()

		if len(apps) < 1 {
			fmt.Println("There are no running ddev applications.")
			os.Exit(0)
		}

		for platformType, sites := range apps {
			platform.RenderAppTable(platformType, sites)
		}
	},
}

DevListCmd represents the list command

View Source
var HostNameCmd = &cobra.Command{
	Use:   "hostname [hostname] [ip]",
	Short: "Manage your hostfile entries.",
	Long:  `Manage your hostfile entries.`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) != 2 {
			log.Fatal("Invalid arguments supplied. Please use 'drud legacy hostname [hostname] [ip]'")
		}

		hostname, ip := args[0], args[1]
		hosts, err := goodhosts.NewHosts()
		if err != nil {
			log.Fatalf("could not open hostfile. %s", err)
		}
		if hosts.Has(ip, hostname) {
			fmt.Println("Entry exists!")
			return
		}

		err = hosts.Add(ip, hostname)
		if err != nil {
			log.Fatal("Could not add hostname")
		}

		if err := hosts.Flush(); err != nil {
			log.Fatalf("could not write hosts file: %s", err)
		}
	},
	PersistentPreRun: func(cmd *cobra.Command, args []string) {},
}

HostNameCmd represents the local command

View Source
var ImportDBCmd = &cobra.Command{
	Use:   "import-db",
	Short: "Import the database of an existing site to the local dev environment.",
	Long: `Import the database of an existing site to the local development environment.
The database can be provided as a SQL dump in a .sql, .sql.gz, .zip, .tgz, or .tar.gz
format. For the zip and tar formats, the path to a .sql file within the archive
can be provided if it is not located at the top-level of the archive.`,
	PreRun: func(cmd *cobra.Command, args []string) {
		if len(args) > 0 {
			err := cmd.Usage()
			util.CheckErr(err)
			os.Exit(0)
		}
		dockerNetworkPreRun()
	},
	Run: func(cmd *cobra.Command, args []string) {
		app, err := platform.GetActiveApp("")
		if err != nil {
			util.Failed("Failed to import database: %v", err)
		}

		if app.SiteStatus() != platform.SiteRunning {
			util.Failed("The site is not running. The site must be running in order to import a database.")
		}

		err = app.ImportDB(dbSource, dbExtPath)
		if err != nil {
			util.Failed("Failed to import database for %s: %v", app.GetName(), err)
		}
		util.Success("Successfully imported database for %v", app.GetName())
	},
}

ImportDBCmd represents the `ddev import-db` command.

View Source
var ImportFileCmd = &cobra.Command{
	Use:   "import-files",
	Short: "Import the uploaded files directory of an existing site to the default public upload directory of your application.",
	Long: `Import the uploaded files directory of an existing site to the default public
upload directory of your application. The files can be provided as a directory
path or an archive in .tar, .tar.gz, .tgz, or .zip format. For the .zip and tar formats,
the path to a directory within the archive can be provided if it is not located at the
top-level of the archive. If the destination directory exists, it will be replaced with
the assets being imported.`,
	PreRun: func(cmd *cobra.Command, args []string) {
		if len(args) > 0 {
			err := cmd.Usage()
			util.CheckErr(err)
			os.Exit(0)
		}
		dockerNetworkPreRun()
	},
	Run: func(cmd *cobra.Command, args []string) {
		app, err := platform.GetActiveApp("")
		if err != nil {
			util.Failed("Failed to import files: %v", err)
		}

		err = app.ImportFiles(fileSource, fileExtPath)
		if err != nil {
			util.Failed("Failed to import files for %s: %v", app.GetName(), err)
		}
		util.Success("Successfully imported files for %v", app.GetName())
	},
}

ImportFileCmd represents the `ddev import-db` command.

View Source
var LocalDevExecCmd = &cobra.Command{
	Use:     "exec <command>",
	Aliases: []string{"."},
	Short:   "Execute a shell command in the container for a service. Uses the web service by default.",
	Long:    `Execute a shell command in the container for a service. Uses the web service by default. To run your command in the container for another service, run "ddev exec --service <service> <cmd>"`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 {
			err := cmd.Usage()
			util.CheckErr(err)
			os.Exit(1)
		}

		app, err := platform.GetActiveApp("")
		if err != nil {
			util.Failed("Failed to exec command: %v", err)
		}

		if strings.Contains(app.SiteStatus(), platform.SiteNotFound) {
			util.Failed("App not running locally. Try `ddev start`.")
		}

		if strings.Contains(app.SiteStatus(), platform.SiteStopped) {
			util.Failed("App is stopped. Run `ddev start` to start the environment.")
		}

		app.DockerEnv()

		err = app.Exec(serviceType, true, args...)
		if err != nil {
			util.Failed("Failed to execute command %s: %v", args, err)
		}
	},
}

LocalDevExecCmd allows users to execute arbitrary bash commands within a container.

View Source
var LocalDevLogsCmd = &cobra.Command{
	Use:   "logs",
	Short: "Get the logs from your running services.",
	Long:  `Uses 'docker logs' to display stdout from the running services.`,
	Run: func(cmd *cobra.Command, args []string) {
		app, err := platform.GetActiveApp("")
		if err != nil {
			util.Failed("Failed to retrieve logs: %v", err)
		}

		if strings.Contains(app.SiteStatus(), platform.SiteNotFound) {
			util.Failed("App not running locally. Try `ddev start`.")
		}

		if strings.Contains(app.SiteStatus(), platform.SiteStopped) {
			util.Failed("App is stopped. Run `ddev start` to start the environment.")
		}

		err = app.Logs(serviceType, follow, timestamp, tail)
		if err != nil {
			util.Failed("Failed to retrieve logs for %s: %v", app.GetName(), err)
		}
	},
}

LocalDevLogsCmd ...

View Source
var LocalDevRMCmd = &cobra.Command{
	Use:     "remove [sitename]",
	Aliases: []string{"rm"},
	Short:   "Remove the local development environment for a site.",
	Long: `Remove the local development environment for a site. You can run 'ddev remove'
from a site directory to remove that site, or you can specify a site to remove
by running 'ddev rm <sitename>'. By default, remove is a non-destructive operation and will
leave database contents intact.

To remove database contents, you may use the --remove-data flag with remove.`,
	Run: func(cmd *cobra.Command, args []string) {
		var siteName string

		if len(args) > 1 {
			util.Failed("Too many arguments provided. Please use `ddev remove` or `ddev remove [appname]`")
		}

		if len(args) == 1 {
			siteName = args[0]
		}

		app, err := platform.GetActiveApp(siteName)
		if err != nil {
			util.Failed("Failed to remove: %v", err)
		}

		if app.SiteStatus() == platform.SiteNotFound {
			util.Failed("App not running locally. Try `ddev start`.")
		}

		err = app.Down(removeData)
		if err != nil {
			util.Failed("Failed to remove %s: %s", app.GetName(), err)
		}

		util.Success("Successfully removed the %s application.\n", app.GetName())
	},
}

LocalDevRMCmd represents the stop command

View Source
var LocalDevReconfigCmd = &cobra.Command{
	Use:   "restart",
	Short: "Restart the local development environment for a site.",
	Long:  `Restart stops the containers for site's environment and starts them back up again.`,
	PreRun: func(cmd *cobra.Command, args []string) {
		if len(args) > 0 {
			err := cmd.Usage()
			util.CheckErr(err)
			os.Exit(0)
		}

		dockerNetworkPreRun()
	},
	Run: func(cmd *cobra.Command, args []string) {
		app, err := platform.GetActiveApp("")
		if err != nil {
			util.Failed("Failed to restart: %v", err)
		}

		fmt.Printf("Restarting environment for %s...", app.GetName())
		err = app.Stop()
		if err != nil {
			util.Failed("Failed to restart %s: %v", app.GetName(), err)
		}

		err = app.Start()
		if err != nil {
			util.Failed("Failed to restart %s: %v", app.GetName(), err)
		}

		util.Success("Successfully restarted %s", app.GetName())
		util.Success("Your application can be reached at: %s", app.URL())
	},
}

LocalDevReconfigCmd rebuilds an apps settings

View Source
var LocalDevSSHCmd = &cobra.Command{
	Use:   "ssh",
	Short: "Starts a shell session in the container for a service. Uses web service by default.",
	Long:  `Starts a shell session in the container for a service. Uses web service by default. To start a shell session for another service, run "ddev ssh --service <service>`,
	Run: func(cmd *cobra.Command, args []string) {
		app, err := platform.GetActiveApp("")
		if err != nil {
			util.Failed("Failed to ssh: %v", err)
		}

		if strings.Contains(app.SiteStatus(), platform.SiteNotFound) {
			util.Failed("App not running locally. Try `ddev start`.")
		}

		if strings.Contains(app.SiteStatus(), platform.SiteStopped) {
			util.Failed("App is stopped. Run `ddev start` to start the environment.")
		}

		app.DockerEnv()

		err = app.Exec(serviceType, false, "bash")
		if err != nil {
			util.Failed("Failed to ssh %s: %s", app.GetName(), err)
		}

	},
}

LocalDevSSHCmd represents the ssh command.

View Source
var LocalDevStopCmd = &cobra.Command{
	Use:   "stop [sitename]",
	Short: "Stop the local development environment for a site.",
	Long: `Stop the local development environment for a site. You can run 'ddev stop'
from a site directory to stop that site, or you can specify a running site
to stop by running 'ddev stop <sitename>.`,
	Run: func(cmd *cobra.Command, args []string) {
		var siteName string

		if len(args) > 1 {
			util.Failed("Too many arguments provided. Please use `ddev stop` or `ddev stop [sitename]`")
		}

		if len(args) == 1 {
			siteName = args[0]
		}

		app, err := platform.GetActiveApp(siteName)
		if err != nil {
			util.Failed("Failed to stop: %v", err)
		}

		err = app.Stop()
		if err != nil {
			util.Failed("Failed to stop containers for %s: %v", app.GetName(), err)
		}

		util.Success("Application has been stopped.")
	},
}

LocalDevStopCmd represents the stop command

View Source
var PantheonAuthCommand = &cobra.Command{
	Use:   "auth-pantheon [token]",
	Short: "Provide a machine token for the global pantheon auth.",
	Long:  "Configure global machine token for pantheon authentication. See https://pantheon.io/docs/machine-tokens/ for instructions on creating a token.",
	Run: func(cmd *cobra.Command, args []string) {

		if len(args) == 0 {
			util.Failed("You must provide a Pantheon machine token, e.g. `ddev auth-pantheon [token]`. See https://pantheon.io/docs/machine-tokens/ for instructions on creating a token.")
		}
		if len(args) != 1 {
			util.Failed("Too many arguments detected. Please provide only your Pantheon Machine token., e.g. `ddev auth-pantheon [token]`. See https://pantheon.io/docs/machine-tokens/ for instructions on creating a token.")
		}
		userDir, err := homedir.Dir()
		util.CheckErr(err)
		sessionLocation := filepath.Join(userDir, ".ddev", "pantheonconfig.json")

		session := pantheon.NewAuthSession(args[0])
		err = session.Auth()
		if err != nil {
			util.Failed("Could not authenticate with pantheon: %v", err)
		}

		err = session.Write(sessionLocation)
		util.Success("Authentication successful!\nYou may now use the `ddev config pantheon` command when configuring sites!")
	},
}

PantheonAuthCommand represents the `ddev auth-pantheon` command

View Source
var PullCmd = &cobra.Command{
	Use:   "pull",
	Short: "Import files and database using a configured provider plugin.",
	Long: `Import files and database using a configured provider plugin.
	Running pull will connect to the configured provider and download + import the
	latest backups.`,
	PreRun: func(cmd *cobra.Command, args []string) {
		if len(args) > 0 {
			err := cmd.Usage()
			util.CheckErr(err)
			os.Exit(0)
		}
		dockerNetworkPreRun()
	},
	Run: func(cmd *cobra.Command, args []string) {
		appImport(skipConfirmation)
	},
}

PullCmd represents the `ddev pull` command.

View Source
var RootCmd = &cobra.Command{
	Use:   "ddev",
	Short: "A CLI for interacting with ddev.",
	Long:  "This Command Line Interface (CLI) gives you the ability to interact with the ddev to create a local development environment.",
	PersistentPreRun: func(cmd *cobra.Command, args []string) {
		ignores := []string{"list", "version", "describe", "config"}
		skip := false
		command := strings.Join(os.Args, " ")

		for _, k := range ignores {
			if strings.Contains(command, " "+k) {
				skip = true
				break
			}
		}

		if !skip {
			_, err := platform.GetPluginApp(plugin)
			if err != nil {
				util.Failed("Plugin %s is not registered", plugin)
			}
		}

		userDdevDir := util.GetGlobalDdevDir()

		updateFile := filepath.Join(userDdevDir, ".update")

		timeToCheckForUpdates, err := updatecheck.IsUpdateNeeded(updateFile, updateInterval)
		if err != nil {
			util.Warning("Could not perform update check: %v", err)
		}

		if timeToCheckForUpdates {
			updateNeeded, updateURL, err := updatecheck.AvailableUpdates("drud", "ddev", version.DdevVersion)

			if err != nil {
				util.Warning("Could not check for updates. This is most often caused by a networking issue.")
				log.Debug(err)
				return
			}

			if updateNeeded {
				util.Warning("\n\nA new update is available! please visit %s to download the update!\n\n", updateURL)
				err = updatecheck.ResetUpdateTime(updateFile)
				if err != nil {
					util.Warning("Could not reset automated update checking interval: %v", err)
				}
			}
		}

		err = dockerutil.CheckDockerVersion(version.DockerVersionConstraint)
		if err != nil {
			if err.Error() == "no docker" {
				if os.Args[1] != "version" && os.Args[1] != "config" {
					util.Failed("Could not connect to docker. Please ensure Docker is installed and running.")
				}
			} else {
				util.Failed("The docker version currently installed does not meet ddev's requirements: %v", err)
			}
		}
	},
}

RootCmd represents the base command when called without any subcommands

View Source
var SequelproLoc = "/Applications/sequel pro.app"

SequelproLoc is where we expect to find the sequel pro.app It's global so it can be mocked in testing.

View Source
var StartCmd = &cobra.Command{
	Use:     "start",
	Aliases: []string{"add"},
	Short:   "Start the local development environment for a site.",
	Long: `Start initializes and configures the web server and database containers to
provide a working environment for development.`,
	PreRun: func(cmd *cobra.Command, args []string) {
		if len(args) > 0 {
			err := cmd.Usage()
			util.CheckErr(err)
			os.Exit(0)
		}

		dockerNetworkPreRun()
	},
	Run: func(cmd *cobra.Command, args []string) {
		appStart()
	},
}

StartCmd represents the add command

Functions

func Execute

func Execute()

Execute adds all child commands to the root command sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL