Example #1
0
func sanitizeMessage(app *kp.Application, message string) string {
	reg := regexp.MustCompile("(?m)^#.*$")
	stripped := reg.ReplaceAllString(message, "")
	content := strings.TrimSpace(stripped)
	if len(content) == 0 {
		app.FatalIfError(errors.New(noMessageProvided), "io")
	}
	return content
}
Example #2
0
func contentsOfFile(app *kp.Application, filePath string) []byte {
	content, err := ioutil.ReadFile(filePath)
	if err != nil {
		if app != nil {
			app.FatalIfError(err, "io")
		} else {
			return []byte{}
		}
	}
	return []byte(content)
}
Example #3
0
func getMessageFromEditor(app *kp.Application, repoPath string) string {
	editor := gg.ConfiguredEditor(repoPath)
	file, err := ioutil.TempFile("", "gitc")
	app.FatalIfError(err, "io")
	path := file.Name()
	file.Write(commentTemplateText(app, repoPath))
	file.Close()
	err = gx.ExecCommand(editor, path)
	app.FatalIfError(err, "io")
	content, err := ioutil.ReadFile(path)
	os.Remove(path)
	app.FatalIfError(err, "io")
	return sanitizeMessage(app, string(content))
}
Example #4
0
// Return the success value, otherwise kill the app with
// the error code specified
func fatalIfError(app *kp.Application, r result.Result, code string) interface{} {
	app.FatalIfError(r.Failure, code)
	return r.Success
}
Example #5
0
func (sc *serverCommand) configure(app *kingpin.Application) {
	cmd := app.Command("server", "run rss2go web server").Action(sc.run)
	cmd.Flag("port", "port to listen on").Default("7999").OverrideDefaultFromEnvar("PORT").Int32Var(&sc.Port)
}