MCPcopy Index your code
hub / github.com/belak/gitdir / runCommand

Function runCommand

utils.go:89–165  ·  view source on GitHub ↗

TODO: see if this can be cleaned up.

( //nolint:funlen
	log *zerolog.Logger,
	cwd string,
	session ssh.Session,
	args []string,
	environ []string,
)

Source from the content-addressed store, hash-verified

87
88// TODO: see if this can be cleaned up.
89func runCommand( //nolint:funlen
90 log *zerolog.Logger,
91 cwd string,
92 session ssh.Session,
93 args []string,
94 environ []string,
95) int {
96 // NOTE: we are explicitly ignoring gosec here because we *only* pass in
97 // known commands here.
98 cmd := exec.Command(args[0], args[1:]...) //nolint:gosec
99 cmd.Dir = cwd
100
101 cmd.Env = append(cmd.Env, environ...)
102 cmd.Env = append(cmd.Env, "PATH="+os.Getenv("PATH"))
103
104 stdin, err := cmd.StdinPipe()
105 if err != nil {
106 log.Error().Err(err).Msg("Failed to get stdin pipe")
107 return 1
108 }
109
110 stdout, err := cmd.StdoutPipe()
111 if err != nil {
112 log.Error().Err(err).Msg("Failed to get stdout pipe")
113 return 1
114 }
115
116 stderr, err := cmd.StderrPipe()
117 if err != nil {
118 log.Error().Err(err).Msg("Failed to get stderr pipe")
119 return 1
120 }
121
122 wg := &sync.WaitGroup{}
123 wg.Add(2)
124
125 if err = cmd.Start(); err != nil {
126 log.Error().Err(err).Msg("Failed to start command")
127 return 1
128 }
129
130 go func() {
131 defer stdin.Close()
132
133 if _, stdinErr := io.Copy(stdin, session); stdinErr != nil {
134 log.Error().Err(err).Msg("Failed to write session to stdin")
135 }
136 }()
137
138 go func() {
139 defer wg.Done()
140
141 if _, stdoutErr := io.Copy(session, stdout); stdoutErr != nil {
142 log.Error().Err(err).Msg("Failed to write stdout to session")
143 }
144 }()
145
146 go func() {

Callers 1

cmdRepoActionMethod · 0.85

Calls 2

getExitStatusFromErrorFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected