-
Notifications
You must be signed in to change notification settings - Fork 20.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changed dumpConfig function to optionally save to file #18327
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,7 +198,19 @@ func dumpConfig(ctx *cli.Context) error { | |
if err != nil { | ||
return err | ||
} | ||
io.WriteString(os.Stdout, comment) | ||
os.Stdout.Write(out) | ||
|
||
if ctx.NArg() > 0 { | ||
f, err := os.OpenFile(ctx.Args().Get(0), os.O_RDWR|os.O_CREATE, 0644) | ||
if err != nil { | ||
return err | ||
} | ||
defer f.Close() | ||
f.WriteString(comment) | ||
f.Write(out) | ||
} else { | ||
io.WriteString(os.Stdout, comment) | ||
os.Stdout.Write(out) | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minot nitpick, might be a bit cleaner to put the stream into a variable and call the writes only once: dump := os.Stdout
if ctx.NArg() > 0 {
dump, err = os.OpenFile(ctx.Args().Get(0), os.O_RDWR|os.O_CREATE|O_TRUNC, 0644)
if err != nil {
return err
}
defer dump.Close()
}
dump.WriteString(comment)
dump.Write(out) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, that code looks much cleaner. I've made updates below |
||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're going to need
O_TRUNC
too