MCPcopy Index your code
hub / github.com/jetify-com/devbox / nixDaemonFlagVal

Function nixDaemonFlagVal

internal/boxcli/setup.go:65–84  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

63// internally. Then setup can decide if it wants to pass in the value of the
64// nixDaemonFlag (if changed).
65func 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}

Callers 1

ensureNixInstalledFunction · 0.85

Calls 1

FwarningfFunction · 0.92

Tested by

no test coverage detected