MCPcopy Index your code
hub / github.com/linuxkit/linuxkit / parseCmd

Function parseCmd

pkg/init/cmd/service/cmd.go:18–50  ·  view source on GitHub ↗
(ctx context.Context, command string, args []string)

Source from the content-addressed store, hash-verified

16)
17
18func 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
52func stopCmd(ctx context.Context, args []string) {
53 log, service, sock, path, _ := parseCmd(ctx, "stop", args)

Callers 3

stopCmdFunction · 0.85
startCmdFunction · 0.85
restartCmdFunction · 0.85

Calls 1

StringMethod · 0.65

Tested by

no test coverage detected