-
Notifications
You must be signed in to change notification settings - Fork 249
[code-cleanup] Rename devbox.Writer to Stderr #1507
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
Conversation
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.
LGTM, thanks!
internal/boxcli/root.go
Outdated
@@ -49,6 +52,8 @@ func RootCmd() *cobra.Command { | |||
SilenceErrors: true, | |||
SilenceUsage: true, | |||
} | |||
command.SetOut(os.Stdout) |
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.
isn't this a no-op?
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.
maybe I am misunderstanding.
I thought the idea behind cmd.OutOrStdout()
was that tests could do command.SetOut
and then inspect the output.
If we're overriding here what the tests may set, then it won't work as desired.
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.
So out
is not set by default in cobra. So cmd.OutOrStdout
returns stdout because out is not set. But cmd.Print
uses OutOrStderr
(don't ask me why, I don't understand it) so it prints to stderr.
I'll fix this by removing cmd.Print
and replacing with fmt.Fprint(cmd.OutOrStdout()
internal/impl/devbox.go
Outdated
@@ -92,7 +89,7 @@ func Open(opts *devopt.Opts) (*Devbox, error) { | |||
nix: &nix.Nix{}, | |||
projectDir: projectDir, | |||
pluginManager: plugin.NewManager(), | |||
writer: opts.Writer, | |||
Stderr: opts.Stderr, |
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.
does Stderr
need to be public?
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.
good point. Will fix.
PrintEnvVars(ctx context.Context) ([]string, error) | ||
PrintGlobalList() error | ||
NixEnv(ctx context.Context, includeHooks bool) (string, error) | ||
PackageNames() []string |
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.
Are these config PackageNames or installable PackageNames?
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.
Just what is in config. This is a no-op (PrintGlobaList used to call PackageNames).
We can chat about whether this is correct or not (I think it's fine), but would rather not change it in this PR.
internal/boxcli/root.go
Outdated
@@ -49,6 +52,8 @@ func RootCmd() *cobra.Command { | |||
SilenceErrors: true, | |||
SilenceUsage: true, | |||
} | |||
command.SetOut(os.Stdout) |
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.
maybe I am misunderstanding.
I thought the idea behind cmd.OutOrStdout()
was that tests could do command.SetOut
and then inspect the output.
If we're overriding here what the tests may set, then it won't work as desired.
internal/boxcli/integrate.go
Outdated
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.
In this case either works, but stdErr is logically correct. 👍
Summary
This renames the devbox
Writer
field to the more accurateStderr
. It changes a few functions that used to print stuff and now they return strings instead.Also renamed a few functions that where called
PrintX
to something more accurate because they don't actually print anything.How to review:
devopt.Opts
this will show all the places where we used to pass in stdout sometimes. Specifically @mohsenari please look at integrate.go. @ipince please look at telemetry.go. I think both of these were wrong.How was it tested?
compiles