cmd

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 21, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RemoveServiceCmd = &cobra.Command{
	Short:   "Force remove a local stargate service",
	Long:    `Force remove a local stargate service`,
	Use:     "remove",
	Example: "stargate service remove",
	Args:    cobra.NoArgs,
	Run: func(cmd *cobra.Command, args []string) {
		client, err := docker.NewClient()
		if err != nil {
			cmd.PrintErrln(err)
			return
		}
		if withCassandra {
			err = client.Remove("cassandra")
			if err != nil {
				cmd.PrintErrln(err)
				return
			}
		}
		err = client.Remove("service")
		if err != nil {
			cmd.PrintErrln(err)
		} else {
			cmd.Println("Success!")
		}
	},
}

RemoveServiceCmd force removes a local instance

View Source
var ServiceCmd = &cobra.Command{
	Short: "Start a local, dockerized service",
	Long: `Start a local, dockerized service

Running 'stargate service -c start' will start both a stargate server and cassandra instance to back it.
Stopping or removing with the cassandra flag will also stop and remove the local cassandra instance.`,
	Use:     "service (start|stop|remove)",
	Example: "stargate service start",
}

ServiceCmd is the parent command for controlling a local stargate instance

View Source
var StartServiceCmd = &cobra.Command{
	Short:   "Start a local, dockerized service server",
	Long:    `Start a local, dockerized service server`,
	Use:     "start [CASSANDRA_HOST]",
	Example: "stargate service start",
	Args:    cobra.MaximumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		client, err := docker.NewClient()
		if err != nil {
			cmd.PrintErrln(err)
			return
		}
		if withCassandra && len(args) == 1 {
			cmd.PrintErrln(errors.New("If you are starting with --with-cassandra, you should not specify a cassandra host"))
			return
		}
		cassandraURL := "stargate-cassandra"
		if len(args) == 1 {
			cassandraURL = args[0]
		}

		if withCassandra {
			err = client.StartCassandra(&docker.StartCassandraOptions{
				DockerImageHost: "docker.io/library/",
				ImageName:       "cassandra",
			})
			if err != nil {
				cmd.PrintErrln(err)
				return
			}
		}

		err = client.StartService(&docker.StartServiceOptions{
			CassandraURL:    cassandraURL,
			ExposedPorts:    []string{"8080"},
			DockerImageHost: "docker.io/",
			ImageName:       "datastax/stargate",
		})
		if err != nil {
			cmd.PrintErrln(err)
		} else {
			cmd.Println("Success!")
		}
	},
}

StartServiceCmd starts a local instance

View Source
var StopServiceCmd = &cobra.Command{
	Short:   "Stop a local stargate service",
	Long:    `Stop a local stargate service`,
	Use:     "stop",
	Example: "stargate service stop",
	Args:    cobra.NoArgs,
	Run: func(cmd *cobra.Command, args []string) {
		client, err := docker.NewClient()
		if err != nil {
			cmd.PrintErrln(err)
			return
		}
		if withCassandra {
			err = client.Stop("cassandra")
			if err != nil {
				cmd.PrintErrln(err)
				return
			}
		}
		err = client.Stop("service")
		if err != nil {
			cmd.PrintErrln(err)
		} else {
			cmd.Println("Success!")
		}
	},
}

StopServiceCmd stops a local instance

View Source
var WatchCmd = &cobra.Command{
	Short: "Watch a schema file and apply schema to a Stargate server",
	Long: `Watch a schema file and apply schema to a Stargate server
	
	if a schema file doesn't exist, an empty one will be created for you`,
	Use:     "watch name path [host]",
	Example: "stargate watch todo ./todo.conf http://server.stargate.com:8080",
	Args:    cobra.MinimumNArgs(3),
	Run: func(cmd *cobra.Command, args []string) {
		watcher, err := fsnotify.NewWatcher()
		if err != nil {
			log.Fatal(err)
		}
		defer watcher.Close()

		name, path, url := args[0], args[1], args[2]

		_, err = os.Stat(path)
		if err != nil {
			emptySchema := []byte("entities {}")
			ioutil.WriteFile(path, emptySchema, 0644)
		} else {
			ApplyWithLog(cmd, name, path, url)
		}

		done := make(chan bool)

		go fileUpdate(cmd, name, path, url, watcher.Events)

		err = watcher.Add(path)
		if err != nil {
			cmd.PrintErr(err)
			os.Exit(1)
		}
		<-done
	},
}

WatchCmd represents the watch command

Functions

func Apply

func Apply(cmd *cobra.Command, name, path, url string) error

Apply sends a schema to server and print output for a user

func ApplyWithLog

func ApplyWithLog(cmd *cobra.Command, name, path, url string) error

ApplyWithLog sends a schema to server and print output for a user

func Execute

func Execute()

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

func SchemaUrl

func SchemaUrl(url string, name string) string

Types

This section is empty.

Jump to

Keyboard shortcuts

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