cmd

package
v0.0.0-...-4c37742 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2020 License: BSD-3-Clause Imports: 26 Imported by: 0

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

View Source
var ConfigCmd = &cobra.Command{
	Use:   "config",
	Short: "An interactive Tokaido config editor",
	Long:  "An interactive Tokaido config editor",
	Run: func(cmd *cobra.Command, args []string) {
		if system.CheckOS() == "windows" {
			fmt.Println(aurora.Red("Sorry! The 'tok config' command isn't available on Windows. Please use `tok config-set` instead"))
			fmt.Println("Please see the Full Tokaido Configuration Reference at https://docs.tokaido.io/en/docs/advanced/tokaido-config-reference for further detail.")
			os.Exit(1)
		}

		initialize.TokConfig("config")
		conf.ValidProjectRoot()
		telemetry.SendCommand("config")

		conf.MainMenu()
	},
}

ConfigCmd - `tok config`

View Source
var ConfigGetCmd = &cobra.Command{
	Use:   "config-get",
	Short: "Get a config property value",
	Long:  "Get a config property value. Eg. `tok config-get drupal path`. See https://tokaido.io/docs/config for a full list of available options",
	Run: func(cmd *cobra.Command, args []string) {
		initialize.TokConfig("config-get")
		conf.ValidProjectRoot()
		telemetry.SendCommand("config-get")

		c, err := conf.GetConfigValueByArgs(args)
		if err != nil {
			log.Fatal(err)
		}

		if c.Kind() == reflect.Struct {
			d := litter.Sdump(c.Interface())
			s := regexp.MustCompile(`(?s)struct {.*?}{`).ReplaceAllString(d, "{")

			fmt.Println(s)
			return
		}

		fmt.Printf("%+v\n", c)
	},
}

ConfigGetCmd - `tok config-get`

View Source
var ConfigSetCmd = &cobra.Command{
	Use:   "config-set",
	Short: "Set a config property value",
	Long:  "Set a config property value. Eg. `tok config-set services solr enabled true`. See https://tokaido.io/docs/config for a full list of available options",
	Run: func(cmd *cobra.Command, args []string) {
		initialize.TokConfig("config-get")
		conf.ValidProjectRoot()
		telemetry.SendCommand("config-set")

		if args[0] == "global" {
			err := conf.SetGlobalConfigValueByArgs(args)
			if err != nil {
				fmt.Println(aurora.Red(err))
			}
		} else {
			conf.SetConfigValueByArgs(args, "project")
		}

	},
}

ConfigSetCmd - `tok config-set`

View Source
var DestroyCmd = &cobra.Command{
	Use:   "destroy",
	Short: "Stop and destroy all containers",
	Long:  "Destroy your Tokaido environment.",
	Run: func(cmd *cobra.Command, args []string) {
		initialize.TokConfig("destroy")
		utils.CheckCmdHard("docker-compose")
		telemetry.SendCommand("destroy")

		docker.HardCheckTokCompose()

		tok.Destroy(conf.GetConfig().Tokaido.Project.Name)
	},
}

DestroyCmd - `tok destroy`

View Source
var ExecCmd = &cobra.Command{
	Use:   "exec",
	Short: "Execute a command inside the Tokaido SSH container",
	Long:  "Execute a command inside the Tokaido SSH container. Alias to `ssh <project-name>.tok -C command`",
	Run: func(cmd *cobra.Command, args []string) {
		if system.CheckOS() == "windows" {
			fmt.Println(aurora.Red("Sorry! The 'tok exec' command isn't available on Windows. Please use SSH instead"))
			os.Exit(1)
		}

		initialize.TokConfig("exec")
		utils.CheckCmdHard("docker-compose")
		telemetry.SendCommand("exec")

		docker.HardCheckTokCompose()

		ssh.StreamConnectCommand(args)
	},
}

ExecCmd - `tok exec`

View Source
var HashCmd = &cobra.Command{
	Use:   "hash",
	Short: "Returns a valid Drupal Hash Salt",
	Long:  "Hash simply generates and returns Drupal hash salt. It is not saved anywhere",
	Run: func(cmd *cobra.Command, args []string) {
		telemetry.SendCommand("hash")
		drupal.Hash()
	},
}

HashCmd - `tok up`

View Source
var InstallCmd = &cobra.Command{
	Use:   "install",
	Short: "Install and use this version of Tokaido",
	Long:  "Install and use this version of Tokaido",
	Run: func(cmd *cobra.Command, args []string) {
		initialize.LoadConfig("install")
		telemetry.SendCommand("install")

		version.SelfInstall(true)
	},
}

InstallCmd - `tok install`

View Source
var ListCmd = &cobra.Command{
	Use:   "list",
	Short: "Lists the status of all Tokaido projects on this system",
	Long:  "Lists the status of all Tokaido projects on this system",
	Run: func(cmd *cobra.Command, args []string) {
		telemetry.SendCommand("list")
		utils.CheckCmdHard("docker-compose")

		tok.List()
	},
}

ListCmd - `tok list`

View Source
var LogsCmd = &cobra.Command{
	Use:   "logs",
	Short: "Output container logs to the console",
	Long:  "Output container logs to the console for all or a single container. Example: tok logs fpm",
	Run: func(cmd *cobra.Command, args []string) {
		initialize.TokConfig("logs")
		telemetry.SendCommand("logs")
		utils.CheckCmdHard("docker-compose")

		docker.HardCheckTokCompose()

		docker.PrintLogs(args)
	},
}

LogsCmd - `tok logs [x]`

View Source
var NewCmd = &cobra.Command{
	Use:   "new [project-name]",
	Short: "Create a new Drupal 8 project",
	Long: `The fastest way to launch new Drupal projects
using open source templates by Tokaido and the community.
Complete documentation is available at https://docs.tokaido.io/tokaido/starting-a-new-drupal-project`,
	Run: func(cmd *cobra.Command, args []string) {
		telemetry.SendCommand("new")
		utils.CheckCmdHard("docker-compose")

		tok.New(args, templateFlag)
	},
}

NewCmd - `tok new {project}`

View Source
var OpenCmd = &cobra.Command{
	Use:   "open",
	Short: "Open the site in your default browser",
	Long:  "Opens your default browser pointing to the Tokaido HTTPS port",
	Run: func(cmd *cobra.Command, args []string) {
		initialize.TokConfig("open")
		telemetry.SendCommand("open")
		utils.CheckCmdHard("docker-compose")

		docker.HardCheckTokCompose()

		system.OpenSite(args, adminFlag)
	},
}

OpenCmd - `tok open`

View Source
var PortsCmd = &cobra.Command{
	Use:   "ports",
	Short: "Display Docker port bindings",
	Long:  "Display all or a single local port binding for a Docker container",
	Run: func(cmd *cobra.Command, args []string) {
		initialize.TokConfig("ports")
		telemetry.SendCommand("ports")
		utils.CheckCmdHard("docker-compose")

		docker.HardCheckTokCompose()

		docker.PrintPorts(args)
	},
}

PortsCmd - `tok ports x`

View Source
var PsCmd = &cobra.Command{
	Use:   "ps",
	Short: "Show Tokaido containers and status",
	Long:  "Alias for running `docker-compose ps`",
	Run: func(cmd *cobra.Command, args []string) {
		initialize.TokConfig("ps")
		telemetry.SendCommand("ps")
		utils.CheckCmdHard("docker-compose")

		docker.HardCheckTokCompose()

		tok.Ps()
	},
}

PsCmd - `tok ps`

View Source
var PurgeCmd = &cobra.Command{
	Use:   "purge",
	Short: "Purge Varnish and Drupal cache",
	Long:  "Purge will purge the Varnish cache and run a drush cache-rebuild operation",
	Run: func(cmd *cobra.Command, args []string) {
		initialize.TokConfig("purge")
		telemetry.SendCommand("purge")
		utils.CheckCmdHard("docker-compose")

		drupal.Purge()
	},
}

PurgeCmd - `tok up`

View Source
var RebuildCmd = &cobra.Command{
	Use:   "rebuild",
	Short: "Rebuilds your Tokaido environment",
	Long:  "Rebuilds your Tokaido environmnet",
	Run: func(cmd *cobra.Command, args []string) {
		initialize.TokConfig("stop")
		telemetry.SendCommand("rebuild")
		utils.CheckCmdHard("docker-compose")

		docker.Stop()
		unison.UnloadSyncService(conf.GetConfig().Tokaido.Project.Name)

		tok.Init(true, false)

		tok.InitMessage()

	},
}

RebuildCmd - `tok rebuild`

View Source
var SnapshotCmd = &cobra.Command{
	Use:   "snapshot [name]",
	Short: "Manage database snapshots saved in .tok/local/snapshots",
	Long:  "Create, restore, database snapshots saved to .tok/local/snapshots. These can be created by Tokaido, or saved SQL dumps from somewhere else.",
	Run: func(cmd *cobra.Command, args []string) {
		initialize.TokConfig("tokaido")
		telemetry.SendCommand("snapshot")
		utils.CheckCmdHard("docker-compose")

		docker.HardCheckTokCompose()

		snapshots.New(args)
	},
}

SnapshotCmd - `tok snapshot new`

View Source
var SnapshotDeleteCmd = &cobra.Command{
	Use:   "delete [id]",
	Short: "Deletes all tokaido snapshots from the .tok/local/snapshots directory",
	Long:  "Creates a new database snapshot and saves it to .tok/local/snapshots with the current UTC date",
	Args:  cobra.MaximumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		initialize.TokConfig("tokaido")
		telemetry.SendCommand("snapshot/delete")
		utils.CheckCmdHard("docker-compose")

		docker.HardCheckTokCompose()

		snapshots.Delete(args)
	},
}

SnapshotDeleteCmd - `tok snapshot cleanup`

View Source
var SnapshotListCmd = &cobra.Command{
	Use:   "list",
	Short: "Lists all snapshots with their current ID",
	Long:  "Lists all snapshots with their current ID",
	Run: func(cmd *cobra.Command, args []string) {
		initialize.TokConfig("tokaido")
		telemetry.SendCommand("snapshot/list")
		utils.CheckCmdHard("docker-compose")

		docker.HardCheckTokCompose()

		snapshots.List()
	},
}

SnapshotListCmd - `tok snapshot list`

View Source
var SnapshotNewCmd = &cobra.Command{
	Use:   "new [name]",
	Short: "Creates a new database snapshot",
	Long:  "Creates a new database snapshot and saves it to .tok/local/snapshots with the current UTC date",
	Run: func(cmd *cobra.Command, args []string) {
		initialize.TokConfig("tokaido")
		telemetry.SendCommand("snapshot/new")
		utils.CheckCmdHard("docker-compose")

		docker.HardCheckTokCompose()

		snapshots.New(args)
	},
}

SnapshotNewCmd - `tok snapshot new`

View Source
var SnapshotRestoreCmd = &cobra.Command{
	Use:   "restore [id]",
	Short: "Restores the specified snapshot id, or provides a list to choose from",
	Long:  "Restores the specified snapshot id, or provides a list to choose from",
	Args:  cobra.MaximumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		initialize.TokConfig("tokaido")
		telemetry.SendCommand("snapshot/restore")
		utils.CheckCmdHard("docker-compose")

		docker.HardCheckTokCompose()

		snapshots.Restore(args)
	},
}

SnapshotRestoreCmd - `tok snapshot cleanup`

View Source
var StatusCmd = &cobra.Command{
	Use:   "status",
	Short: "Have Tokaido perform a self-test",
	Long:  "Checks the status of your Tokaido environment",
	Run: func(cmd *cobra.Command, args []string) {
		initialize.TokConfig("status")
		telemetry.SendCommand("status")
		utils.CheckCmdHard("docker-compose")

		fmt.Println()

		docker.HardCheckTokCompose()

		if conf.GetConfig().Global.Syncservice == "unison" {
			ok := unison.CheckBackgroundService(conf.GetConfig().Tokaido.Project.Name)
			if ok {
				console.Println(`πŸ™‚  Background sync service is running`, "√")
			} else {
				fmt.Println(aurora.Red(`πŸ˜“  The Unison background sync service is not running    `))
				fmt.Println()
				pn := conf.GetConfig().Tokaido.Project.Name
				switch system.CheckOS() {
				case "macos":
					h := fs.HomeDir()
					lp := filepath.Join(h, "Library", "Logs", "tokaido.sync."+pn)
					fmt.Printf("You can check Unison logs in the...\n%s and \n%s files\n", aurora.Bold(lp+".out"), aurora.Bold(lp+".err"))
					fmt.Printf("Or you can run %s to reconfigure and restart it\n", "tok up")
				case "linux":
					sn := "tokaido-sync-" + pn + ".service"
					fmt.Printf("You can check Unison logs by running 'journalctl -u %s'", sn)
				}
				fmt.Println()
				os.Exit(1)
			}
		}

		ok := docker.StatusCheck("", conf.GetConfig().Tokaido.Project.Name)
		if ok {
			console.Println(`😊  All containers are running`, "√")
		} else {
			console.Println(`πŸ˜“  Tokaido containers are not running`, "Γ—")
			fmt.Println(`    It appears that some or all of the Tokaido containers are offline.

    View the status of your containers with 'tok ps'

    You can try to fix this by running 'tok up', or by running 'tok repair'.`)
		}

		ok = ssh.CheckKey()
		if ok {
			console.Println("πŸ˜€  SSH access is configured", "√")
		} else {
			console.Println("πŸ˜“  SSH access is not configured", "Γ—")
			fmt.Println("    Your SSH access to the Drush container looks broken.")
			fmt.Println("    You should be able to run 'tok repair' to attempt to fix this automatically")
		}

		err := drupal.CheckContainer()

		if err == nil {
			fmt.Println()
			console.Println(`🍜  Checks have passed successfully`, "")
			fmt.Println()
			console.Println(`🌎  Run 'tok open' to open the environment in your default browser`, "")
			fmt.Println()
		} else {
			fmt.Println()
			fmt.Println(aurora.Yellow("πŸ™…  Some checks failed! You might be able to fix this by running `tok rebuild`    "))
			fmt.Println()
		}
	},
}

StatusCmd - `tok status`

View Source
var StopCmd = &cobra.Command{
	Use:   "stop",
	Short: "Gracefully stop/pause your Tokaido environment",
	Long:  "Gracefully stop/pause your Tokaido environment. Restart with `tok up`",
	Run: func(cmd *cobra.Command, args []string) {
		initialize.TokConfig("stop")
		telemetry.SendCommand("stop")
		utils.CheckCmdHard("docker-compose")

		docker.HardCheckTokCompose()

		docker.Stop()

		unison.StopSyncService(conf.GetConfig().Tokaido.Project.Name)
	},
}

StopCmd - `tok stop`

View Source
var SurveyCmd = &cobra.Command{
	Use:   "survey",
	Short: "Take a 3 question survey to share your Tokaido feedback",
	Long:  "Take a 3 question survey to share your Tokaido feedback",
	Run: func(cmd *cobra.Command, args []string) {
		telemetry.SendCommand("survey")
		utils.CheckCmdHard("docker-compose")

		telemetry.Survey()
	},
}

SurveyCmd - `tok survey`

View Source
var SyncCmd = &cobra.Command{
	Use:   "sync",
	Short: "Perform a one-time sync of your Tokaido environment and local host",
	Long:  "Perform a one-time sync of your Tokaido environment and local host",
	Run: func(cmd *cobra.Command, args []string) {
		telemetry.SendCommand("sync")
		console.Println(`πŸ›    This command was deprecated in Tokaido 1.6.0.

    Tokaido no longer relies on a background sync service, so you
    should not need to use this command. If you are having problems
    with sync please come visit us on the #Tokaido channel in the
    official Drupal Slack.`, "")

	},
}

SyncCmd - `tok sync`

View Source
var SyscheckCmd = &cobra.Command{
	Use:   "syscheck",
	Short: "Test if your local system is ready to run Tokaido",
	Long:  "Test if your local system is ready to run Tokaido",
	Run: func(cmd *cobra.Command, args []string) {
		initialize.TokConfig("syscheck")
		telemetry.SendCommand("syscheck")
		utils.CheckCmdHard("docker-compose")

		docker.HardCheckTokCompose()

		fmt.Println()
		console.Println(`πŸš…  Checking Drupal for compatibility with Tokaido`, "")
		fmt.Println()

		drupal.CheckLocal()

		console.Println(`πŸš‰  Drupal compatibility checks complete!`, "")
		fmt.Println()
	},
}

SyscheckCmd - `tok syscheck`

View Source
var TestCmd = &cobra.Command{
	Use:   "test",
	Short: "Run all available tests",
	Long:  "Runs all available test suites for Drupal with TestCafe",
	Run: func(cmd *cobra.Command, args []string) {
		initialize.TokConfig("test")
		telemetry.SendCommand("test")
		fmt.Println()
		utils.CheckCmdHard("docker-compose")

		docker.HardCheckTokCompose()

		ok := docker.StatusCheck("", conf.GetConfig().Tokaido.Project.Name)
		if !ok {
			log.Fatalf("Tokaido containers must be running in order to start automated tests. Have you run `tok up`?")
		}

		testcafe.RunDrupalTests(useExistingDBFlag)
	},
}

TestCmd - `tok test`

View Source
var TestPhpcbfCmd = &cobra.Command{
	Use:   "test:phpcbf",
	Short: "Run PHPCodeSniffer linting and attempt to fix automatically",
	Long:  "Run the PHPCodeSniffer linter and attempt to fix automatically",
	Run: func(cmd *cobra.Command, args []string) {
		initialize.TokConfig("test")
		telemetry.SendCommand("test:phpcbf")
		utils.CheckCmdHard("docker-compose")

		docker.HardCheckTokCompose()

		ok := docker.StatusCheck("", conf.GetConfig().Tokaido.Project.Name)
		if !ok {
			log.Fatalf("Tokaido containers must be running in order to start automated tests. Have you run `tok up`?")
		}

		phpcs.CheckReqs()
		phpcs.RunLinterFix()
	},
}

TestPhpcbfCmd - `tok test:phpcbf`

View Source
var TestPhpcsCmd = &cobra.Command{
	Use:   "test:phpcs",
	Short: "Run PHPCodeSniffer linting",
	Long:  "Run the PHPCodeSniffer linter",
	Run: func(cmd *cobra.Command, args []string) {
		initialize.TokConfig("test")
		telemetry.SendCommand("test:phpcs")
		utils.CheckCmdHard("docker-compose")

		docker.HardCheckTokCompose()

		ok := docker.StatusCheck("", conf.GetConfig().Tokaido.Project.Name)
		if !ok {
			log.Fatalf("Tokaido containers must be running in order to start automated tests. Have you run `tok up`?")
		}

		phpcs.CheckReqs()
		phpcs.RunLinter()
	},
}

TestPhpcsCmd - `tok test:phpcs`

View Source
var UpCmd = &cobra.Command{
	Use:   "up",
	Short: "Start a Tokaido local development environment",
	Long:  "Start a Tokaido local development environment",
	Run: func(cmd *cobra.Command, args []string) {
		initialize.TokConfig("up")
		telemetry.SendCommand("up")
		utils.CheckCmdHard("docker-compose")

		tok.Init(conf.GetConfig().Tokaido.Yes, true)
		tok.InitMessage()
	},
}

UpCmd - `tok up`

View Source
var UpgradeCmd = &cobra.Command{
	Use:   "upgrade",
	Short: "Upgrade to the latest version of Tokaido",
	Long:  "Upgrade to the latest version of Tokaido",
	Run: func(cmd *cobra.Command, args []string) {
		initialize.LoadConfig("upgrade")
		telemetry.SendCommand("upgrade")

		version.Upgrade()
	},
}

UpgradeCmd - `tok upgrade`

View Source
var VersionCmd = &cobra.Command{
	Use:   "version [version]",
	Short: "Print Tokdaido version information",
	Long:  "Print Tokdaido version information including 'Build Date', 'Compiler' and 'Platform'",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 || args[0] == "" {
			version.Display()

			return
		}

		initialize.LoadConfig("version")
		telemetry.SendCommand("version select (" + args[0] + ")")

		version.Select(args[0])
	},
}

VersionCmd - `tok version`

View Source
var WatchCmd = &cobra.Command{
	Use:   "watch",
	Short: "Maintain a foreground sync service using Unison",
	Long:  "Watch your files for changes and sync them to your Tokaido environment, until you exit.",
	Run: func(cmd *cobra.Command, args []string) {
		telemetry.SendCommand("watch")
		fmt.Println(`πŸ›    This command was deprecated in Tokaido 1.6.0.

    Tokaido no longer relies on a background sync service, so you
    should not need to use this command. If you are having problems
    with sync please come visit us on the #Tokaido channel in the
    official Drupal Slack.`)

	},
}

WatchCmd - `tok watch`

Functions ΒΆ

func Execute ΒΆ

func Execute()

Execute - Root executable

func RootCmd ΒΆ

func RootCmd() *cobra.Command

RootCmd will setup and return the root command

Types ΒΆ

This section is empty.

Jump to

Keyboard shortcuts

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