Exemple #1
0
func runBegin(cmd *cobra.Command, args []string) (exit int) {
	if len(args) > 1 {
		stderr("begin: incorrect number of arguments")
		return 1
	}

	if debug {
		if len(args) == 0 {
			stderr("Beginning build with an empty ACI")
		} else {
			stderr("Beginning build with %s", args[0])
		}
	}

	var err error
	if len(args) == 0 {
		err = lib.Begin(tmpacipath(), "")
	} else {
		err = lib.Begin(tmpacipath(), args[0])
	}

	if err != nil {
		stderr("begin: %v", err)
		return 1
	}

	return 0
}
Exemple #2
0
func runBegin(cmd *cobra.Command, args []string) (exit int) {
	if len(args) > 1 {
		stderr("begin: incorrect number of arguments")
		return 1
	}

	ex, err := util.Exists(path.Join(contextpath, workprefix))
	if err != nil {
		stderr("begin: %v", err)
		return 1
	}
	if ex {
		stderr("begin: build already in progress in this working dir")
		return 1
	}

	err = os.MkdirAll(path.Join(contextpath, workprefix), 0755)
	if err != nil {
		stderr("begin: %v", err)
		return 1
	}

	lockfile, err := getLock()
	if err != nil {
		stderr("begin: %v", err)
		return 1
	}
	defer func() {
		if err := releaseLock(lockfile); err != nil {
			stderr("begin: %v", err)
			exit = 1
		}
	}()

	if debug {
		if len(args) == 0 {
			stderr("Beginning build with an empty ACI")
		} else {
			stderr("Beginning build with %s", args[0])
		}
	}

	if len(args) == 0 {
		err = lib.Begin(tmpacipath(), "")
	} else {
		err = lib.Begin(tmpacipath(), args[0])
	}

	if err != nil {
		stderr("begin: %v", err)
		return 1
	}

	return 0
}
Exemple #3
0
// runWrapper return a func(cmd *cobra.Command, args []string) that internally
// will add command function return code and the reinsertion of the "--" flag
// terminator.
func runWrapper(cf func(cmd *cobra.Command, args []string) (exit int)) func(cmd *cobra.Command, args []string) {
	return func(cmd *cobra.Command, args []string) {
		if aciToModify == "" {
			cmdExitCode = cf(cmd, args)
			return
		}

		contextualCommands := []string{"begin", "end", "abort"}
		command := strings.Split(cmd.Use, " ")[0]
		for _, cc := range contextualCommands {
			if command == cc {
				stderr("Can't use the --modify flag with %s.", command)
				cmdExitCode = 1
				return
			}
		}

		var err error
		contextpath, err = ioutil.TempDir("", "acbuild-")
		if err != nil {
			stderr("%v", err)
			cmdExitCode = 1
			return
		}
		defer os.Remove(contextpath)

		err = lib.Begin(tmpacipath(), aciToModify)
		if err != nil {
			stderr("%v", err)
			cmdExitCode = 1
			return
		}

		cmdExitCode = cf(cmd, args)

		err = lib.End(tmpacipath(), aciToModify, path.Join(contextpath,
			workprefix), true)
		if err != nil {
			stderr("%v", err)
			cmdExitCode = 1
			return
		}
	}
}