-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
118 lines (99 loc) · 3.39 KB
/
main.go
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package main
import (
"fmt"
"os"
"github.com/docker/docker/pkg/namesgenerator"
"github.com/ml-doom/invoker/internal"
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{Use: "higgsfield"}
var experimentCmd = &cobra.Command{Use: "experiment", Short: "Experiment commands"}
func runCmdFunc() *cobra.Command {
cmd := &cobra.Command{
Use: "run",
Short: "Run an experiment",
Run: func(cmd *cobra.Command, args []string) {
internal.Run(internal.RunArgs{
ExperimentName: internal.ParseOrExit[string](cmd, "experiment_name"),
ProjectName: internal.ParseOrExit[string](cmd, "project_name"),
Port: internal.ParseOrExit[int](cmd, "port"),
RunName: internal.ParseOrExit[string](cmd, "run_name"),
NProcPerNode: internal.ParseOrExit[int](cmd, "nproc_per_node"),
Hosts: internal.ParseOrExit[[]string](cmd, "hosts"),
MaxRepeats: -1,
ContainerName: internal.ParseOrNil[string](cmd, "container_name"),
Rest: args,
})
},
}
cmd.PersistentFlags().String("experiment_name", "", "name of the experiment")
cmd.PersistentFlags().String("project_name", "", "name of the project")
cmd.PersistentFlags().Int("port", 1234, "port to run the experiment on")
cmd.PersistentFlags().String("run_name", "", "name of the run")
cmd.PersistentFlags().Int("nproc_per_node", 1, "number of processes per node")
cmd.PersistentFlags().StringSlice("hosts", []string{}, "list of hosts to run the experiment on")
cmd.PersistentFlags().String("container_name", "", "name of the container, optional")
return cmd
}
func killCmdFunc() *cobra.Command {
cmd := &cobra.Command{
Use: "kill",
Short: "Kill an experiment",
Run: func(cmd *cobra.Command, args []string) {
internal.Kill(internal.KillArgs{
ProjectName: internal.ParseOrExit[string](cmd, "project_name"),
Hosts: internal.ParseOrExit[[]string](cmd, "hosts"),
ExperimentName: internal.ParseOrExit[string](cmd, "experiment_name"),
ContainerName: internal.ParseOrNil[string](cmd, "container_name"),
})
},
}
cmd.PersistentFlags().String("experiment_name", "", "name of the experiment")
cmd.PersistentFlags().StringSlice("hosts", []string{}, "list of hosts to run the experiment on")
cmd.PersistentFlags().String("project_name", "", "name of the project")
cmd.PersistentFlags().String("container_name", "", "name of the container, optional")
return cmd
}
func decodeSecrets() *cobra.Command {
cmd := &cobra.Command{
Use: "decode-secrets",
Short: "Decode secrets",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
internal.DecodeSecrets(args[0])
},
}
return cmd
}
func randomName() *cobra.Command {
cmd := &cobra.Command{
Use: "random-name",
Short: "Generate a random name",
Run: func(cmd *cobra.Command, args []string) {
fmt.Print(namesgenerator.GetRandomName(0))
},
}
return cmd
}
func randomPort() *cobra.Command {
cmd := &cobra.Command{
Use: "random-port",
Short: "Generate a random port",
Run: func(cmd *cobra.Command, args []string) {
fmt.Print(internal.GeneratePort())
},
}
return cmd
}
func main() {
experimentCmd.AddCommand(runCmdFunc())
experimentCmd.AddCommand(killCmdFunc())
rootCmd.AddCommand(decodeSecrets())
rootCmd.AddCommand(randomName())
rootCmd.AddCommand(randomPort())
rootCmd.AddCommand(experimentCmd)
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}