clideployment

package
v3.0.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2018 License: MIT Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ErrNoNamespaceSpecified chkitErrors.Err = "no namespace specified"
)

Variables

View Source
var Create = &cobra.Command{
	Use:     "deployment",
	Aliases: aliases,
	Short:   "create new deployment",
	Long: `Creates new deployment.
Has an one-line, suitable for integration with other tools, and an interactive wizard mode`,
	Run: func(cmd *cobra.Command, args []string) {
		depl := deplactive.DefaultDeployment()
		if cmd.Flag("file").Changed {
			var err error
			depl, err = deplactive.FromFile(createDeplConfig.File)
			if err != nil {
				logrus.WithError(err).Errorf("unable to load deployment data from file %s", createDeplConfig.File)
				fmt.Printf("Unable to load deployment data from file :(\n%v", err)
				os.Exit(1)
			}
		}
		depl, err := deplactive.Wizard(deplactive.Config{
			Deployment: &depl,
		})
		if err != nil {
			logrus.WithError(err).Errorf("unable to create deployment")
			fmt.Println(err)
			os.Exit(1)
		}
		for {
			_, err := (&activekit.Menu{
				Items: []*activekit.MenuItem{
					{
						Label: "Push deployment to server",
						Action: func() error {
							err := context.GlobalContext.Client.CreateDeployment(context.GlobalContext.Namespace, depl)
							if err != nil {
								logrus.WithError(err).Errorf("unable to create deployment %q", depl.Name)
								fmt.Println(err)
								return nil
							}
							fmt.Printf("Congratulations! Deployment %q created!\n", depl.Name)
							return nil
						},
					},
					{
						Label: "Edit deployment",
						Action: func() error {
							var err error
							depl, err = deplactive.Wizard(deplactive.Config{
								Deployment: &depl,
							})
							if err != nil {
								logrus.WithError(err).Errorf("unable to create deployment")
								fmt.Println(err)
								os.Exit(1)
							}
							return nil
						},
					},
					{
						Label: "Print to terminal",
						Action: activekit.ActionWithErr(func() error {
							if data, err := depl.RenderYAML(); err != nil {
								return err
							} else {
								upBorders := strings.Repeat("_", text.Width(data))
								downBorders := strings.Repeat("_", text.Width(data))
								fmt.Printf("%s\n\n%s\n%s\n", upBorders, data, downBorders)
							}
							return nil
						}),
					},
					{
						Label: "Save to file",
						Action: func() error {
							filename, _ := activekit.AskLine("Print filename: ")
							data, err := depl.RenderJSON()
							if err != nil {
								return err
							}
							if err := ioutil.WriteFile(filename, []byte(data), os.ModePerm); err != nil {
								logrus.WithError(err).Errorf("unable to save deployment %q to file", depl.Name)
								fmt.Printf("Unable to save deployment to file :(\n%v", err)
								return nil
							}
							fmt.Printf("OK\n")
							return nil
						},
					},
					{
						Label: "Exit",
						Action: func() error {
							if yes, _ := activekit.Yes("Are you sure you want to exit?"); yes {
								os.Exit(0)
							}
							return nil
						},
					},
				},
			}).Run()
			if err != nil {
				logrus.WithError(err).Errorf("error while menu execution")
				angel.Angel(err)
				os.Exit(1)
			}
		}
	},
}
View Source
var Get = &cobra.Command{
	Use:     "deployment",
	Short:   "shows deployment data",
	Long:    "Shows deployment data",
	Example: "namespace deployment_names... [-n namespace_label]",
	Aliases: aliases,
	Run: func(command *cobra.Command, args []string) {
		deplData, err := func() (model.Renderer, error) {
			switch len(args) {
			case 0:
				logrus.Debugf("getting deployment from %q", context.GlobalContext.Namespace)
				list, err := context.GlobalContext.Client.GetDeploymentList(context.GlobalContext.Namespace)
				if err != nil {
					return nil, err
				}
				return list, nil
			default:
				deplNames := strset.NewSet(args)
				var showList deployment.DeploymentList = make([]deployment.Deployment, 0) // prevents panic
				list, err := context.GlobalContext.Client.GetDeploymentList(context.GlobalContext.Namespace)
				if err != nil {
					return nil, err
				}
				for _, depl := range list {
					if deplNames.Have(depl.Name) {
						showList = append(showList, depl)
					}
				}
				return showList, nil
			}
		}()
		if err != nil {
			logrus.WithError(err).Errorf("unable to get deployment data")
			fmt.Printf("%v :(\n", err)
			return
		}
		if err := configuration.ExportData(deplData, configuration.ExportConfig{}); err != nil {
			logrus.WithError(err).Errorf("unable to export data")
			angel.Angel(err)
		}
	},
}

Functions

func Delete

func Delete(ctx *context.Context) *cobra.Command

Types

This section is empty.

Jump to

Keyboard shortcuts

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