env

package
v0.12.0-beta Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &cobra.Command{
	Use:   "env [environment-name]",
	Short: "Execute an environment",
	Long:  "Execute an environment by name. The environment will be searched for in the active profile and all repository configurations. Tasks are executed concurrently and environment variables are set globally.",
	Args:  cobra.RangeArgs(0, 1),
	RunE: func(cmd *cobra.Command, args []string) error {
		if showJSON && len(args) > 0 {
			return fmt.Errorf("--json is only valid without an environment argument")
		}
		if len(args) == 0 {
			active := env.Get()
			if showJSON {
				enc := json.NewEncoder(cmd.OutOrStdout())
				enc.SetIndent("", "  ")
				return enc.Encode(envEntry{Name: active, Active: active != ""})
			}
			if active == "" {
				cmd.PrintErrln("No active environment set.")
			} else {
				cmd.Println("Active environment:", active)
			}
			return nil
		}

		name := args[0]
		if !env.Contains(name) {
			cmd.PrintErrln("Environment not found:", name)
			return nil
		}

		cmd.Println("Setting up environment:", name)
		err := raid.WithMutationLock(func() error {
			if err := env.Set(name); err != nil {
				cmd.PrintErrln("Failed to switch environment:", err)
				return err
			}
			if err := raid.ForceLoad(); err != nil {
				cmd.PrintErrln("Failed to reload profile:", err)
				return err
			}
			if err := env.Execute(env.Get()); err != nil {
				cmd.PrintErrln("Failed to execute environment:", err)
				return err
			}
			return nil
		})
		if err != nil {
			return nil
		}
		cmd.Println("Environment executed successfully.")
		return nil
	},
}
View Source
var ListEnvCmd = &cobra.Command{
	Use:   "list",
	Short: "List environments",
	RunE: func(cmd *cobra.Command, args []string) error {
		envs := env.ListAll()
		active := env.Get()

		if listJSON {
			out := make([]envEntry, 0, len(envs))
			for _, name := range envs {
				out = append(out, envEntry{Name: name, Active: name == active})
			}
			enc := json.NewEncoder(cmd.OutOrStdout())
			enc.SetIndent("", "  ")
			return enc.Encode(out)
		}

		if len(envs) == 0 {
			fmt.Fprintln(cmd.OutOrStdout(), "No environments found.")
			return nil
		}
		fmt.Fprintln(cmd.OutOrStdout(), "Available environments:")
		for _, name := range envs {
			fmt.Fprintf(cmd.OutOrStdout(), "\t%s\n", name)
		}
		return nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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