Print version info to stdout instead of stderr (#1503)

## Description

Previously we were printing the version information with `corso --version` to stderr. This changes it to stdout.

## Type of change

<!--- Please check the type of change your PR introduces: --->
- [ ] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Test
- [ ] 💻 CI/Deployment
- [x] 🐹 Trivial/Minor

## Issue(s)

<!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. -->
* fixes https://github.com/alcionai/corso/issues/1361

## Test Plan

<!-- How will this be tested prior to merging.-->
- [x] 💪 Manual
- [ ]  Unit test
- [ ] 💚 E2E
This commit is contained in:
Abin Simon 2022-11-21 22:49:53 +05:30 committed by GitHub
parent 73b4aa6ff6
commit a2860eed10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 5 deletions

View File

@ -40,7 +40,7 @@ var corsoCmd = &cobra.Command{
func handleCorsoCmd(cmd *cobra.Command, args []string) error { func handleCorsoCmd(cmd *cobra.Command, args []string) error {
v, _ := cmd.Flags().GetBool("version") v, _ := cmd.Flags().GetBool("version")
if v { if v {
print.Infof(cmd.Context(), "Corso\nversion: "+version) print.Outf(cmd.Context(), "Corso\nversion: "+version)
return nil return nil
} }

View File

@ -89,6 +89,38 @@ func err(w io.Writer, s ...any) {
fmt.Fprint(w, msg...) fmt.Fprint(w, msg...)
} }
// Out prints the params to cobra's output writer (stdOut by default)
// if s is nil, prints nothing.
func Out(ctx context.Context, s ...any) {
out(getRootCmd(ctx).OutOrStdout(), s...)
}
// out is the testable core of Out()
func out(w io.Writer, s ...any) {
if len(s) == 0 {
return
}
fmt.Fprint(w, s...)
fmt.Fprintf(w, "\n")
}
// Out prints the formatted strings to cobra's output writer (stdOut by default)
// if t is empty, prints nothing.
func Outf(ctx context.Context, t string, s ...any) {
outf(getRootCmd(ctx).OutOrStdout(), t, s...)
}
// outf is the testable core of Outf()
func outf(w io.Writer, t string, s ...any) {
if len(t) == 0 {
return
}
fmt.Fprintf(w, t, s...)
fmt.Fprintf(w, "\n")
}
// Info prints the params to cobra's error writer (stdErr by default) // Info prints the params to cobra's error writer (stdErr by default)
// if s is nil, prints nothing. // if s is nil, prints nothing.
func Info(ctx context.Context, s ...any) { func Info(ctx context.Context, s ...any) {
@ -138,14 +170,12 @@ type Printable interface {
// Item prints the printable, according to the caller's requested format. // Item prints the printable, according to the caller's requested format.
func Item(ctx context.Context, p Printable) { func Item(ctx context.Context, p Printable) {
print(getRootCmd(ctx).OutOrStdout(), p) printItem(getRootCmd(ctx).OutOrStdout(), p)
} }
// print prints the printable items, // print prints the printable items,
// according to the caller's requested format. // according to the caller's requested format.
// func printItem(w io.Writer, p Printable) {
//revive:disable:redefines-builtin-id
func print(w io.Writer, p Printable) {
if outputAsJSON || outputAsJSONDebug { if outputAsJSON || outputAsJSONDebug {
outputJSON(w, p, outputAsJSONDebug) outputJSON(w, p, outputAsJSONDebug)
return return