Example #1
0
// so much boilerplate
func ZipInit() {

	f := func(s []string) (r Result, e string) {
		r, err := ZipTarget(s[0]) // need to convert error returned into a string or change all other string errors to use the same struct
		// e = "Not Implemented." // return an error regardless
		fmt.Println(err)
		return
	}

	AppendCommand("zip", 1, ZipTarget)

	//this header bit is also always the same
	w := func(s []string) (r Result, e string) {
		l := s[1] + " " + s[2] // TESTING ONLY - awful code

		//important bit is to get the number of parameters consumed by the func and applying them to the func
		v, err := write.WriteStringToFile(s[0], l) // This is the only bit that really varies

		r = Result{v, ""} // result + error handling are always the same
		if err != nil {
			e = err.Error()
		}
		// returns are always the same
		return
	}

	AppendCommand("writer", 2, w)

	r := func(s []string) (r Result, e string) {
		v, err := write.ReplaceGivenStringInFile(s[0], s[1], s[2])

		r = Result{v, ""}
		if err != nil {
			e = err.Error()
		}
		return
	}

	AppendCommand("replacer", 3, r)
}
Example #2
0
// ?? Should probably not be required to return a result, and should instead cast any error or
//      string returned into a result by the command code
func (t Replacer) Run(s []string) (r Result) {
	res, err := write.ReplaceGivenStringInFile(s[0], s[1], s[2])
	return Result{res, err}
}