Skip to content

Commit d2abcf5

Browse files
authored
profiles: Add --detach/-d flag (#57)
This new flag makes the detached mode opt-in, allowing for better user experience.
2 parents b0ae038 + adba762 commit d2abcf5

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

cmd/cli/start.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/urfave/cli/v3"
1313
)
1414

15-
var selfcall bool
15+
var detach bool
1616

1717
func startCommand() *cli.Command {
1818
cmd := &cli.Command{
@@ -43,16 +43,19 @@ qubesome start -git https://github.com/qubesome/sample-dotfiles i3
4343
&cli.StringFlag{
4444
Name: "runner",
4545
Destination: &runner,
46+
Usage: "sets what runner to be used, this will override the value set at the qubesome.config. Options: docker or podman.",
4647
},
4748
&cli.BoolFlag{
4849
Name: "interactive",
4950
Aliases: []string{"i"},
5051
Destination: &interactive,
52+
Usage: "enables interactive mode, which runs the profile container but holds any windows manager execution. Use this for troubleshooting.",
5153
},
5254
&cli.BoolFlag{
53-
Sources: cli.EnvVars("QUBESOME_SELFCALL"),
54-
Destination: &selfcall,
55-
Hidden: true,
55+
Name: "detach",
56+
Aliases: []string{"d"},
57+
Destination: &detach,
58+
Usage: "start the profile process in the background. This cannot be used in conjunction with --interactive nor --debug.",
5659
},
5760
},
5861
Arguments: []cli.Argument{
@@ -66,11 +69,18 @@ qubesome start -git https://github.com/qubesome/sample-dotfiles i3
6669
Action: func(ctx context.Context, cmd *cli.Command) error {
6770
// When a profile is started, it starts an inception server
6871
// so that the containerised Windows Manager is able to execute
69-
// new container workloads. This self-calls qubesome and leave it
70-
// running so that the main process exits right away.
71-
if !debug && !interactive && !selfcall {
72-
cmd := exec.Command(os.Args[0], os.Args[1:]...) //nolint
73-
cmd.Env = append(cmd.Env, "QUBESOME_SELFCALL=true")
72+
// new container workloads.
73+
// Running on detached mode makes a background call to qubesome,
74+
// leaving it running so that the main process can exit right away.
75+
if !debug && !interactive && detach {
76+
var args []string
77+
for _, arg := range os.Args[1:] {
78+
if arg == "-d" || arg == "-detach" {
79+
continue
80+
}
81+
args = append(args, arg)
82+
}
83+
cmd := exec.Command(os.Args[0], args...) //nolint
7484
cmd.Env = append(cmd.Env, os.Environ()...)
7585
cmd.Stdout = nil
7686
cmd.Stderr = nil
@@ -80,10 +90,10 @@ qubesome start -git https://github.com/qubesome/sample-dotfiles i3
8090
}
8191

8292
if err := cmd.Start(); err != nil {
83-
return fmt.Errorf("failed to daemonise profile start: %w", err)
93+
return fmt.Errorf("failed to run profile start in detach mode: %w", err)
8494
}
8595

86-
fmt.Printf("[%d] profile start as daemon\n", cmd.Process.Pid)
96+
fmt.Printf("[%d] %q profile start detached\n", cmd.Process.Pid, targetProfile)
8797
os.Exit(0)
8898
}
8999

0 commit comments

Comments
 (0)