Skip to content

Commit

Permalink
refactor helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
zerowidth committed Apr 3, 2023
1 parent 3d1af35 commit 19d553c
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,7 @@ Examples:
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
noNewline, _ := cmd.Flags().GetBool("no-newline")
if noNewline {
fmt.Print(out)
} else {
fmt.Println(out)
}
printOptionalNewline(cmd, out)
},
}

Expand Down Expand Up @@ -88,12 +83,7 @@ Example:
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
noNewline, _ := cmd.Flags().GetBool("no-newline")
if noNewline {
fmt.Print(out)
} else {
fmt.Println(out)
}
printOptionalNewline(cmd, out)
},
}

Expand Down Expand Up @@ -121,12 +111,7 @@ Example:
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
noNewline, _ := cmd.Flags().GetBool("no-newline")
if noNewline {
fmt.Print(out)
} else {
fmt.Println(out)
}
printOptionalNewline(cmd, out)
},
}

Expand Down Expand Up @@ -213,3 +198,12 @@ func title(input string, sanitize bool) (string, error) {

return title, nil
}

func printOptionalNewline(cmd *cobra.Command, output string) {
noNewline, _ := cmd.Flags().GetBool("no-newline")
if noNewline {
fmt.Print(output)
} else {
fmt.Println(output)
}
}

0 comments on commit 19d553c

Please sign in to comment.