run

package
v0.12.6 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RunCmd = &cobra.Command{
	Use:   "run [environment] -- [command]",
	Short: "Run your app with the specified environment",
	Long: `
The run command executes your application with the specified environment variables.

Usage:
  hyphen env run [environment] -- [command]

Examples:
  hyphen env run production -- go run main.go
  hyphen env run staging -- node server.js
  hyphen env run -- go run main.go (uses default environment)
`,
	Run: func(cmd *cobra.Command, args []string) {
		printer = cprint.NewCPrinter(flags.VerboseFlag)

		var envName string
		var childCommand []string

		separatorIndex := cmd.ArgsLenAtDash()

		if separatorIndex == -1 || separatorIndex == 0 {

			envName = "default"
			childCommand = args
		} else {
			envName = args[0]
			childCommand = args[separatorIndex:]
		}

		if len(childCommand) == 0 {
			printer.Error(cmd, errors.New("No command specified"))
			return
		}

		manifest, err := manifest.Restore()
		if err != nil {
			printer.Error(cmd, errors.Wrap(err, "Failed to restore manifest"))
			return
		}

		mergedEnvVars, err := loadAndMergeEnvFiles(envName, manifest)
		if err != nil {
			printer.Error(cmd, err)
			return
		}

		if err := runCommandWithEnv(childCommand, mergedEnvVars); err != nil {
			printer.Error(cmd, errors.Wrap(err, "Command execution failed"))
			return
		}
	},
}

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