-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.go
More file actions
59 lines (54 loc) · 1.61 KB
/
start.go
File metadata and controls
59 lines (54 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"context"
"fmt"
"github.com/urfave/cli/v3"
"github.com/winter-again/flow/internal/tmux"
)
func Start() *cli.Command {
socketName, socketPath := tmux.GetDefaultSocket()
return &cli.Command{
Name: "start",
Aliases: []string{"s"},
Usage: "Start and attach to new tmux server for flow to manage",
// TODO: this seems to check exclusivity, but is the behavior correct? It prints the
// help and a warning under
// It could be a bug closed by this PR: https://github.com/urfave/cli/issues/2146
MutuallyExclusiveFlags: []cli.MutuallyExclusiveFlags{
{
Flags: [][]cli.Flag{
{
&cli.StringFlag{
Name: "name",
Aliases: []string{"n"},
Value: socketName,
Usage: "tmux server socket name",
Destination: &socketName,
},
},
{
&cli.StringFlag{
Name: "path",
Aliases: []string{"p"},
Value: socketPath,
Usage: "tmux server socket path",
Destination: &socketPath,
},
},
},
},
},
Action: func(ctx context.Context, cmd *cli.Command) error {
server := tmux.NewServer(socketName, socketPath)
_, _, err := server.Start()
if err != nil {
return cli.Exit(fmt.Errorf("error while starting server with socket name '%s' and socket path '%s': %w", server.SocketName, server.SocketPath, err), 1)
}
_, _, err = server.Attach("")
if err != nil {
return cli.Exit(fmt.Errorf("error while attaching to server with socket name '%s' and socket path '%s': %w", server.SocketName, server.SocketPath, err), 1)
}
return nil
},
}
}