// 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 } } }
func runEnd(cmd *cobra.Command, args []string) (exit int) { if len(args) == 0 { cmd.Usage() return 1 } if len(args) > 1 { stderr("end: incorrect number of arguments") return 1 } lockfile, err := getLock() if err != nil { stderr("end: %v", err) return 1 } // Lock will be released when lib.End deletes the folder containing the // lockfile. if debug { stderr("Ending build. Writing completed ACI to %s", args[0]) } err = lib.End(tmpacipath(), args[0], path.Join(contextpath, workprefix), overwrite) if err != nil { stderr("end: %v", err) // In the event of an error the lockfile won't have been removed, so // let's release the lock now if err := releaseLock(lockfile); err != nil { stderr("end: %v", err) } return 1 } return 0 }