We return a closure to avoid printing the warning every time and just printing it if we actually need the value of the flag. TODO: devbox.Open should run nix.EnsureNixInstalled and do this logic internally. Then setup can decide if it wants to pass in the value of the nixDaemonFlag (if changed).
(cmd *cobra.Command)
| 63 | // internally. Then setup can decide if it wants to pass in the value of the |
| 64 | // nixDaemonFlag (if changed). |
| 65 | func nixDaemonFlagVal(cmd *cobra.Command) func() *bool { |
| 66 | return func() *bool { |
| 67 | if !cmd.Flags().Changed(nixDaemonFlag) { |
| 68 | if os.Geteuid() == 0 { |
| 69 | ux.Fwarningf( |
| 70 | cmd.ErrOrStderr(), |
| 71 | "Running as root. Installing Nix in multi-user mode.\n", |
| 72 | ) |
| 73 | return lo.ToPtr(true) |
| 74 | } |
| 75 | return nil |
| 76 | } |
| 77 | |
| 78 | val, err := cmd.Flags().GetBool(nixDaemonFlag) |
| 79 | if err != nil { |
| 80 | return nil |
| 81 | } |
| 82 | return &val |
| 83 | } |
| 84 | } |
no test coverage detected