set

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:   "set",
	Short: "Set new or update the existing command in the current project configuration",
	Long: `Set new or update the existing command in the current project configuration

- command name is a one word: without spaces, dashes and underscores are allowed
- command should be double-quoted if it the command contain spaces

For example:

  1build set test "npm run test"
  1build set npm-test "npm run test"
  1build set npm_test "npm run test"

This will update the current project configuration file.`,
	Args: cobra.ExactArgs(2),
	PreRun: func(cmd *cobra.Command, args []string) {
		_, err := config.LoadOneBuildConfiguration()
		if err != nil {
			fmt.Println(err)
			utils.ExitError()
		}

		commandName := args[0]
		matched, _ := regexp.MatchString(`^[a-zA-Z0-9\-_]+$`, commandName)

		if !matched {
			fmt.Println("1build set: '" + commandName + "' is not a valid command name. See '1build set --help'.")
			utils.ExitError()
		}
	},
	Run: func(cmd *cobra.Command, args []string) {
		commandName := args[0]
		commandValue := args[1]

		configuration, err := buildAndSetCommand(commandName, commandValue)

		if err != nil {
			fmt.Println(err)
			return
		}

		_ = config.WriteConfigFile(configuration)
	},
}

Cmd cobra command for setting one build configuration command

Functions

func IndexOfCommandIfPresent

func IndexOfCommandIfPresent(configuration config.OneBuildConfiguration, commandName string) int

IndexOfCommandIfPresent returns index in configuration for command if exists

Types

This section is empty.

Jump to

Keyboard shortcuts

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