MCPcopy
hub / github.com/kubesphere/kubekey / ModuleCommand

Function ModuleCommand

pkg/modules/command/command.go:63–83  ·  view source on GitHub ↗

* The Command module executes shell commands on remote hosts and returns their output. This module allows users to run arbitrary shell commands and capture their output. Configuration: Users can specify the command to execute: command: "ls -l" # The shell command to execute Usage Examples in P

(ctx context.Context, opts internal.ExecOptions)

Source from the content-addressed store, hash-verified

61
62// ModuleCommand handles the "command" module, executing shell commands on remote hosts
63func ModuleCommand(ctx context.Context, opts internal.ExecOptions) (string, string, error) {
64 // get host variable
65 ha, err := opts.GetAllVariables()
66 if err != nil {
67 return internal.StdoutFailed, internal.StderrGetHostVariable, err
68 }
69 // get connector
70 conn, err := opts.GetConnector(ctx)
71 if err != nil {
72 return internal.StdoutFailed, internal.StderrGetConnector, err
73 }
74 defer conn.Close(ctx)
75 // command string
76 command, err := variable.Extension2String(ha, opts.Args)
77 if err != nil {
78 return internal.StdoutFailed, internal.StderrParseArgument, err
79 }
80 // execute command
81 stdout, stderr, err := conn.ExecuteCommand(ctx, string(command))
82 return string(stdout), string(stderr), err
83}

Callers

nothing calls this directly

Calls 5

Extension2StringFunction · 0.92
GetAllVariablesMethod · 0.80
GetConnectorMethod · 0.80
CloseMethod · 0.65
ExecuteCommandMethod · 0.65

Tested by

no test coverage detected