diff --git a/cmd/cli/start.go b/cmd/cli/start.go index 648132f..a637709 100644 --- a/cmd/cli/start.go +++ b/cmd/cli/start.go @@ -12,7 +12,7 @@ import ( "github.com/urfave/cli/v3" ) -var selfcall bool +var detach bool func startCommand() *cli.Command { cmd := &cli.Command{ @@ -43,16 +43,19 @@ qubesome start -git https://github.com/qubesome/sample-dotfiles i3 &cli.StringFlag{ Name: "runner", Destination: &runner, + Usage: "sets what runner to be used, this will override the value set at the qubesome.config. Options: docker or podman.", }, &cli.BoolFlag{ Name: "interactive", Aliases: []string{"i"}, Destination: &interactive, + Usage: "enables interactive mode, which runs the profile container but holds any windows manager execution. Use this for troubleshooting.", }, &cli.BoolFlag{ - Sources: cli.EnvVars("QUBESOME_SELFCALL"), - Destination: &selfcall, - Hidden: true, + Name: "detach", + Aliases: []string{"d"}, + Destination: &detach, + Usage: "start the profile process in the background. This cannot be used in conjunction with --interactive nor --debug.", }, }, Arguments: []cli.Argument{ @@ -66,11 +69,18 @@ qubesome start -git https://github.com/qubesome/sample-dotfiles i3 Action: func(ctx context.Context, cmd *cli.Command) error { // When a profile is started, it starts an inception server // so that the containerised Windows Manager is able to execute - // new container workloads. This self-calls qubesome and leave it - // running so that the main process exits right away. - if !debug && !interactive && !selfcall { - cmd := exec.Command(os.Args[0], os.Args[1:]...) //nolint - cmd.Env = append(cmd.Env, "QUBESOME_SELFCALL=true") + // new container workloads. + // Running on detached mode makes a background call to qubesome, + // leaving it running so that the main process can exit right away. + if !debug && !interactive && detach { + var args []string + for _, arg := range os.Args[1:] { + if arg == "-d" || arg == "-detach" { + continue + } + args = append(args, arg) + } + cmd := exec.Command(os.Args[0], args...) //nolint cmd.Env = append(cmd.Env, os.Environ()...) cmd.Stdout = nil cmd.Stderr = nil @@ -80,10 +90,10 @@ qubesome start -git https://github.com/qubesome/sample-dotfiles i3 } if err := cmd.Start(); err != nil { - return fmt.Errorf("failed to daemonise profile start: %w", err) + return fmt.Errorf("failed to run profile start in detach mode: %w", err) } - fmt.Printf("[%d] profile start as daemon\n", cmd.Process.Pid) + fmt.Printf("[%d] %q profile start detached\n", cmd.Process.Pid, targetProfile) os.Exit(0) }