Skip to content

[global] Fix global services #1484

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 2 commits into from
Sep 16, 2023
Merged

[global] Fix global services #1484

merged 2 commits into from
Sep 16, 2023

Conversation

mikeland73
Copy link
Contributor

Summary

cobra doesn't chain PersistentPreRunE. So if a parent declares one and a child declares it as well, the parent function is ignored. global uses PersistentPreRunE to set the global project directory. The services command was running it to ensure nix is installed. The child replaced the parent, so we were never setting th

The fix here is a bit ugly but it solves them problem.

There's a UX issue I rediscovered while testing this. When adding global packages the environment is not automatically refreshed. This means services wont work until a new shell is opened or if the user does eval "$(devbox global shellenv)" manually.

How was it tested?

devbox global add nginx
eval "$(devbox global shellenv)"
devbox global services up

@mikeland73 mikeland73 requested review from savil and Lagoja September 15, 2023 23:08
@@ -19,8 +19,12 @@ func globalCmd() *cobra.Command {
globalCmd := &cobra.Command{}

*globalCmd = cobra.Command{
Use: "global",
Short: "Manage global devbox packages",
Use: "global",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of copy-pasting, it'll be nice to use a common variable...

persistentPreRunE := setGlobalConfigForDelegatedCommands(globalCmd)

*globalCmd = cobra.Command{
 		Use:   "global",
 		PersistentPreRunE: persistentPreRunE,
 		 ...
 		 }
 		 
 		 ...
 addCommandAndHideConfigFlag(
 		 globalCmd,
 		servicesCmd(persistentPreRunE),
 ),

@mikeland73 mikeland73 merged commit 39b7f0e into main Sep 16, 2023
@mikeland73 mikeland73 deleted the landau/fix-global-services branch September 16, 2023 00:16
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.

2 participants