MCPcopy
hub / github.com/google/gvisor / Run

Function Run

runsc/cli/cli.go:63–321  ·  view source on GitHub ↗

Run runs the binary, whose behavior is determined by the subcommand passed on the command line. commands is a mapping of all top level runsc commands to their command group name. helpTopics is a list of additional help topics.

(commands map[util.SubCommand]string, helpTopics []subcommands.Command)

Source from the content-addressed store, hash-verified

61// on the command line. commands is a mapping of all top level runsc commands
62// to their command group name. helpTopics is a list of additional help topics.
63func Run(commands map[util.SubCommand]string, helpTopics []subcommands.Command) {
64 // Set the start time as soon as possible.
65 startTime := starttime.Get()
66
67 // Help flags, and help and flags commands, are generated automatically.
68 flagHelp := flag.Bool("help", false, "show information about runsc subcommands and exit")
69 flag.BoolVar(flagHelp, "h", false, "equivalent to the 'help' flag")
70 cdr := subcommands.DefaultCommander
71 help := NewHelp(cdr)
72 subcommands.Register(help, "")
73 subcommands.Register(subcommands.FlagsCommand(), "")
74
75 // Register all commands.
76 for cmd, group := range commands {
77 subcommands.Register(&helpCommandWrapper{wrapped: cmd}, group)
78 }
79
80 // Register help commands.
81 for _, cmd := range helpTopics {
82 help.Register(cmd)
83 }
84
85 // Register with the main command line.
86 config.RegisterFlags(flag.CommandLine)
87
88 // Register version flag if it is not already defined.
89 if flag.Lookup(versionFlagName) == nil {
90 flag.Bool(versionFlagName, false, "show version and exit.")
91 }
92
93 // All subcommands must be registered before flag parsing.
94 flag.Parse()
95
96 // Are we showing help?
97 if *flagHelp {
98 help.printTopLevelHelp()
99 os.Exit(0)
100 }
101
102 // Are we showing the version?
103 if flag.Get(flag.Lookup(versionFlagName).Value).(bool) {
104 // The format here is the same as runc.
105 fmt.Fprintf(os.Stdout, "runsc version %s\n", version.Version())
106 fmt.Fprintf(os.Stdout, "spec: %s\n", specutils.Version)
107 os.Exit(0)
108 }
109
110 // Create a buffered emitter to capture logs during initialization. This is
111 // needed because log package initializes the target with an emitter that
112 // writes to stderr (which is reserved for the application). This would
113 // prevent any intermediate logs from leaking to stderr. This is later
114 // drained to the right target once the emitter is created below.
115 bufEmitter := &bufferedEmitter{}
116 log.SetTarget(bufEmitter)
117
118 config.WarnOnDeprecatedFlagUsage(flag.CommandLine)
119
120 // Create a new Config from the flags.

Callers 2

mainFunction · 0.92
MainFunction · 0.92

Calls 15

RegisterMethod · 0.95
printTopLevelHelpMethod · 0.95
drainMethod · 0.95
GetFunction · 0.92
RegisterFlagsFunction · 0.92
GetFunction · 0.92
VersionFunction · 0.92
SetTargetFunction · 0.92
NewFromFlagsFunction · 0.92
FatalfFunction · 0.92
OpenFileFunction · 0.92

Tested by

no test coverage detected