Fix some errors with format patterns
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 2 Dec 2015 22:37:40 +0000 (23:37 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 2 Dec 2015 22:37:40 +0000 (23:37 +0100)
See #1502

commands/hugo.go
commands/undraft.go

index 0cd9523488bfc6e383a81fe73b326df21c0b31b0..e1a469e858559e00ec4abce385089fdb25ea8459 100644 (file)
@@ -57,12 +57,20 @@ func (u commandError) isUserError() bool {
        return u.userError
 }
 
-func newUserError(messages ...interface{}) commandError {
-       return commandError{s: fmt.Sprintln(messages...), userError: true}
+func newUserError(a ...interface{}) commandError {
+       return commandError{s: fmt.Sprintln(a...), userError: true}
 }
 
-func newSystemError(messages ...interface{}) commandError {
-       return commandError{s: fmt.Sprintln(messages...), userError: false}
+func newUserErrorF(format string, a ...interface{}) commandError {
+       return commandError{s: fmt.Sprintf(format, a...), userError: true}
+}
+
+func newSystemError(a ...interface{}) commandError {
+       return commandError{s: fmt.Sprintln(a...), userError: false}
+}
+
+func newSystemErrorF(format string, a ...interface{}) commandError {
+       return commandError{s: fmt.Sprintf(format, a...), userError: false}
 }
 
 // catch some of the obvious user errors from Cobra.
index 89b56c95e5ca5f59dd43d8db2f34bb14f220b302..891e1e1959a0f198b482c0640c0f62b0befd20d2 100644 (file)
@@ -59,17 +59,17 @@ func Undraft(cmd *cobra.Command, args []string) error {
 
        w, err := undraftContent(p)
        if err != nil {
-               return newSystemError("an error occurred while undrafting %q: %s", location, err)
+               return newSystemErrorF("an error occurred while undrafting %q: %s", location, err)
        }
 
        f, err = os.OpenFile(location, os.O_WRONLY|os.O_TRUNC, 0644)
        if err != nil {
-               return newSystemError("%q not be undrafted due to error opening file to save changes: %q\n", location, err)
+               return newSystemErrorF("%q not be undrafted due to error opening file to save changes: %q\n", location, err)
        }
        defer f.Close()
        _, err = w.WriteTo(f)
        if err != nil {
-               return newSystemError("%q not be undrafted due to save error: %q\n", location, err)
+               return newSystemErrorF("%q not be undrafted due to save error: %q\n", location, err)
        }
        return nil
 }