(ctx context.Context, command string, args []string)
| 16 | ) |
| 17 | |
| 18 | func parseCmd(ctx context.Context, command string, args []string) (*log.Entry, string, string, string, string) { |
| 19 | invoked := filepath.Base(os.Args[0]) |
| 20 | flags := flag.NewFlagSet(command, flag.ExitOnError) |
| 21 | flags.Usage = func() { |
| 22 | fmt.Printf("USAGE: %s %s [service]\n\n", invoked, command) |
| 23 | fmt.Printf("Options:\n") |
| 24 | flags.PrintDefaults() |
| 25 | } |
| 26 | |
| 27 | sock := flags.String("sock", defaultSocket, "Path to containerd socket") |
| 28 | path := flags.String("path", defaultServicesPath, "Path to service configs") |
| 29 | |
| 30 | dumpSpec := flags.String("dump-spec", "", "Dump container spec to file before start") |
| 31 | |
| 32 | if err := flags.Parse(args); err != nil { |
| 33 | log.Fatal("Unable to parse args") |
| 34 | } |
| 35 | args = flags.Args() |
| 36 | |
| 37 | if len(args) != 1 { |
| 38 | fmt.Println("Please specify the service") |
| 39 | flags.Usage() |
| 40 | os.Exit(1) |
| 41 | } |
| 42 | |
| 43 | service := args[0] |
| 44 | |
| 45 | log := log.WithFields(log.Fields{ |
| 46 | "service": service, |
| 47 | }) |
| 48 | |
| 49 | return log, service, *sock, *path, *dumpSpec |
| 50 | } |
| 51 | |
| 52 | func stopCmd(ctx context.Context, args []string) { |
| 53 | log, service, sock, path, _ := parseCmd(ctx, "stop", args) |
no test coverage detected