Skip to content

[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

Merged
merged 6 commits into from
Sep 27, 2023
Merged

Conversation

mikeland73
Copy link
Contributor

Summary

This renames the devbox Writer field to the more accurate Stderr. 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:

  • grep for 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.
  • Please take a look at functions that used to print stuff and now return strings (i.e. Info and PrintGlobalList). I tried to keep formatting identical so nothing should change.

How was it tested?

compiles

Copy link
Contributor

@ipince ipince left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@@ -49,6 +52,8 @@ func RootCmd() *cobra.Command {
SilenceErrors: true,
SilenceUsage: true,
}
command.SetOut(os.Stdout)
Copy link
Contributor

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?

Copy link
Collaborator

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.

Copy link
Contributor Author

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()

@@ -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,
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

@@ -49,6 +52,8 @@ func RootCmd() *cobra.Command {
SilenceErrors: true,
SilenceUsage: true,
}
command.SetOut(os.Stdout)
Copy link
Collaborator

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.

Copy link
Collaborator

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. 👍

@mikeland73 mikeland73 merged commit 5ed2c80 into main Sep 27, 2023
@mikeland73 mikeland73 deleted the landau/rename-writer branch September 27, 2023 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants