runner

package
v1.0.7-nightly Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InitCommand = &cobra.Command{
	Use:   "init",
	Short: "initialize a kl-config file",
	Long:  `use this command to initialize a kl-config file`,

	Run: func(cmd *cobra.Command, _ []string) {

		aName := fn.ParseStringFlag(cmd, "account")
		filePath := fn.ParseKlFile(cmd)
		initFile, err := client.GetKlFile(filePath)

		if err != nil {

			envs, err := server.ListEnvs(fn.MakeOption("accountName", aName))
			if err != nil {
				fn.PrintError(err)
				return
			}

			packages := []string{"vim", "git"}

			defEnv := ""
			if len(envs) != 0 {
				de, err := fzf.FindOne(envs, func(item server.Env) string {
					return item.Metadata.Name
				}, fzf.WithPrompt("Select default environment >"))

				if err != nil {
					fn.PrintError(err)
					return
				}

				defEnv = de.Metadata.Name
			} else {
				fn.Warn("no environment found, please create environments from dashboard")
			}

			accName, err := client.CurrentAccountName()
			if err != nil {
				fn.PrintError(err)
				return
			}

			initFile = &client.KLFileType{
				AccountName: accName,
				Version:     "v1",
				DefaultEnv:  defEnv,
				Packages:    packages,
				EnvVars:     []client.EnvType{{Key: "SAMPLE", Value: fn.Ptr("sampleValue")}},
				Mounts:      client.Mounts{},
			}
			if defEnv == "" {
				fn.Warn("No environment found, Please create environments from dashboard\n")
			} else {
				fn.Log("default env set to: ", defEnv)
			}

		} else {
			fn.Log("file already present \n")
		}

		if err = client.WriteKLFile(*initFile); err != nil {
			fn.PrintError(err)
			return
		}

		fn.Log("Initialized file ", client.GetConfigPath())
	},
}

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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