Skip to content

Commit

Permalink
archiver-manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
arnab-baishnab committed Jan 23, 2025
1 parent 9d35a8e commit 0871891
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 41 deletions.
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
go.bytebuilders.dev/license-verifier/kubernetes v0.14.4
gocloud.dev v0.40.0
gomodules.xyz/envsubst v0.2.0
gomodules.xyz/go-sh v0.1.0
gomodules.xyz/go-sh v0.1.1-0.20250117070215-e08594acad2a
gomodules.xyz/pointer v0.1.0
gomodules.xyz/x v0.0.17
k8s.io/api v0.30.3
Expand Down Expand Up @@ -174,5 +174,3 @@ require (
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
)

replace gomodules.xyz/go-sh v0.1.0 => github.com/anisurrahman75/go-sh v0.0.0-20241030063656-336ab30e016a
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ github.com/Masterminds/semver/v3 v3.3.0 h1:B8LGeaivUe71a5qox1ICM/JLl0NqZSW5CHyL+
github.com/Masterminds/semver/v3 v3.3.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
github.com/PuerkitoBio/purell v1.2.1 h1:QsZ4TjvwiMpat6gBCBxEQI0rcS9ehtkKtSpiUnd9N28=
github.com/PuerkitoBio/purell v1.2.1/go.mod h1:ZwHcC/82TOaovDi//J/804umJFFmbOHPngi8iYYv/Eo=
github.com/anisurrahman75/go-sh v0.0.0-20241030063656-336ab30e016a h1:vds1Kj0c/3uTud2/W66GorqmFhPcqHteeSX+6uD3+gc=
github.com/anisurrahman75/go-sh v0.0.0-20241030063656-336ab30e016a/go.mod h1:N8IrjNiYppUI/rxENYrWD6FOrSxSyEZnIekPEWM7LP0=
github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2 h1:7Ip0wMmLHLRJdrloDxZfhMm0xrLXZS8+COSu2bXmEQs=
github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU=
Expand Down Expand Up @@ -438,6 +436,8 @@ golang.org/x/xerrors v0.0.0-20240716161551-93cc26a95ae9 h1:LLhsEBxRTBLuKlQxFBYUO
golang.org/x/xerrors v0.0.0-20240716161551-93cc26a95ae9/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90=
gomodules.xyz/envsubst v0.2.0 h1:piG4OcpUa/Mu7LxSo+2Ye8JH7pXXWM2XuCD8Ic7Hdwc=
gomodules.xyz/envsubst v0.2.0/go.mod h1:eB1KRKtXx6RSpl+WYxE8gFE7DhNJCoorHzSij7X3AQo=
gomodules.xyz/go-sh v0.1.1-0.20250117070215-e08594acad2a h1:Pz5BeoJLbzDpkeVu/YUmfOpaJVq/CoQuZUFl0G5WnVM=
gomodules.xyz/go-sh v0.1.1-0.20250117070215-e08594acad2a/go.mod h1:N8IrjNiYppUI/rxENYrWD6FOrSxSyEZnIekPEWM7LP0=
gomodules.xyz/jsonpatch/v2 v2.4.0 h1:Ci3iUJyx9UeRx7CeFN8ARgGbkESwJK+KB9lLcWxY/Zw=
gomodules.xyz/jsonpatch/v2 v2.4.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuBJT4moAY=
gomodules.xyz/mergo v0.3.13 h1:q6cL/MMXZH/MrR2+yjSihFFq6UifXqjwaqI48B6cMEM=
Expand Down
43 changes: 43 additions & 0 deletions vendor/gomodules.xyz/go-sh/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ These are some of its features:
* pipe command
* shell build-in commands echo & test
* timeout support
* run multiple concurrent leaf commands using a single pipe input

Examples are important:

Expand Down Expand Up @@ -80,6 +81,48 @@ By default, pipeline returns error only if the last command exit with a non-zero

By default, pipelines's std-error is set to last command's std-error. However, you can also combine std-errors of all commands into pipeline's std-error using `session.PipeStdErrors = true`.

By default, pipeline returns error only if the last command exit with a non-zero status. However, you can also enable `pipefail` option like `bash`. In that case, pipeline returns error if any of the commands fail and for multiple failed commands, it returns the error of rightmost failed command.

session := sh.NewSession()
session.PipeFail = true
session.Command("cat", "unknown-file").Command("echo").Run()


Designing a Command Chain to Run Multiple Concurrent Leaf Commands Using a Single Pipe Input.

Features be like:
* **Input Sharing**: All leaf commands take the same input from a pipe.
* **Separate Environments**: Each leaf command runs with its own environment variables.
* **Output Aggregation**: Outputs from all commands are combined into a single result.
* **Error Handling**: Errors are collected and included in the output (e.g., shell or variable).
* **Timeouts**: Each command has same timeout and will apply simultaneously.

Below is an example of multiple concurrent leaf commands using a single pipe input

s := sh.NewSession()
s.ShowCMD = true
s.Command("echo", "hello world").LeafCommand("xargs").LeafCommand("xargs")
s.Run()

Below is an example of each leaf command runs with its own environment variables

s := sh.NewSession()
s.ShowCMD = true
var args1,args2 []interface{}

mp := make(map[string]string)
mp["COMPANY_NAME"] = "APPSCODE"
args1 = append(args1, "COMPANY_NAME")
args1 = append(args1, mp)
s.LeafCommand("printenv", args1...)

mp["COMPANY_NAME"] = "GOOGLE"
args2 = append(args2, "COMPANY_NAME")
args2 = append(args2, mp)
s.LeafCommand("printenv", args2...)

s.Run()

for more information, it better to see docs.
[![Go Walker](http://gowalker.org/api/v1/badge)](http://gowalker.org/gomodules.xyz/go-sh)

Expand Down
88 changes: 53 additions & 35 deletions vendor/gomodules.xyz/go-sh/pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,34 +56,14 @@ func (s *Session) executeCommandChain(index int, stdin *io.PipeReader) error {
if index >= len(s.cmds) {
return nil
}
pipeCount := s.determinePipeCount(index)
pipeReaders, pipeWriters := createPipes(pipeCount)

var writers []io.Writer
for _, writer := range pipeWriters {
writers = append(writers, writer)
s.pipeWriters = append(s.pipeWriters, writer)
}
multiWriter := io.MultiWriter(writers...)
pipeReaders, pipeWriters := createPipes(s.determinePipeCount(index))

cmd := s.cmds[index]
cmd.Stdin = stdin
if index == 0 {
cmd.Stdin = s.Stdin
}
cmd.Stdin = s.selectCmdStdin(index, stdin)
cmd.Stdout, cmd.Stderr = s.configureCmdOutput(index, pipeWriters)

if s.isLastCommand(index) && len(s.leafCmds) == 0 {
// If it's the last command and no leaf commands
cmd.Stdout = s.Stdout
cmd.Stderr = s.Stderr
} else {
// Otherwise, pipe output to the next command
cmd.Stdout = multiWriter
cmd.Stderr = os.Stderr
if s.PipeStdErrors {
cmd.Stderr = s.Stderr
}
}
s.pipeWriters = append(s.pipeWriters, pipeWriters...)

if err := cmd.Start(); err != nil {
return err
Expand All @@ -95,24 +75,62 @@ func (s *Session) executeCommandChain(index int, stdin *io.PipeReader) error {
return s.executeCommandChain(index+1, pipeReaders[0])
}

func (s *Session) selectCmdStdin(index int, stdin *io.PipeReader) io.Reader {
if index == 0 {
return s.Stdin
}
return stdin
}

func (s *Session) configureCmdOutput(index int, pipeWriters []*io.PipeWriter) (io.Writer, io.Writer) {
if s.isLastCommand(index) && len(s.leafCmds) == 0 {
return s.Stdout, s.Stderr
}

stdout := io.MultiWriter(pipeWritersToWriters(pipeWriters)...)
var stderr io.Writer = os.Stderr
if s.PipeStdErrors {
stderr = s.Stderr
}

return stdout, stderr
}

func pipeWritersToWriters(pipeWriters []*io.PipeWriter) []io.Writer {
var writers []io.Writer
for _, writer := range pipeWriters {
writers = append(writers, writer)
}
return writers
}

func (s *Session) executeLeafCommands(readers []*io.PipeReader) error {
for idx, cmd := range s.leafCmds {
cmd.Stdin = s.Stdin
if readers != nil && idx < len(readers) {
cmd.Stdin = readers[idx]
}
cmd.Stdin = s.selectLeafCmdStdin(idx, readers)
cmd.Stdout = s.selectLeafCmdStdout()
cmd.Stderr = s.Stderr
if s.enableErrsBuffer {
cmd.Stderr = cmd.Stdout
}
cmd.Stderr = s.selectLeafCmdStderr()

if err := cmd.Start(); err != nil {
return err
}
}
return nil
}

func (s *Session) selectLeafCmdStdin(index int, readers []*io.PipeReader) io.Reader {
if readers != nil {
return readers[index]
}
return s.Stdin
}

func (s *Session) selectLeafCmdStderr() io.Writer {
if s.enableErrsBuffer {
return s.selectLeafCmdStdout()
}
return s.Stderr
}

func (s *Session) selectLeafCmdStdout() io.Writer {
if s.enableOutputBuffer {
cmdOutput := &bytes.Buffer{}
Expand Down Expand Up @@ -154,11 +172,11 @@ func (s *Session) displayCommandChain() {
}
return result
}
primaryCmds, backupCmds := joinCmds(s.cmds), joinCmds(s.leafCmds)
primaryCmds, leafCmds := joinCmds(s.cmds), joinCmds(s.leafCmds)

totalCmd := strings.Join(primaryCmds, " | ")
if len(backupCmds) > 0 {
totalCmd += " | " + strings.Join(backupCmds, " , ")
if len(leafCmds) > 0 {
totalCmd += " | " + strings.Join(leafCmds, " , ")
}

s.writePrompt(totalCmd)
Expand Down
1 change: 1 addition & 0 deletions vendor/gomodules.xyz/go-sh/sh.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ func (s *Session) appendCmd(cmd string, args []string, cwd Dir, env map[string]s
s.cmds = make([]*exec.Cmd, 0)
s.leafCmds = make([]*exec.Cmd, 0)
s.pipeWriters = make([]*io.PipeWriter, 0)
s.leafOutputBuffer = make([]*bytes.Buffer, 0)
}
for k, v := range s.Env {
if _, ok := env[k]; !ok {
Expand Down
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ golang.org/x/xerrors/internal
gomodules.xyz/envsubst
gomodules.xyz/envsubst/parse
gomodules.xyz/envsubst/path
# gomodules.xyz/go-sh v0.1.0 => github.com/anisurrahman75/go-sh v0.0.0-20241030063656-336ab30e016a
# gomodules.xyz/go-sh v0.1.1-0.20250117070215-e08594acad2a
## explicit; go 1.15
gomodules.xyz/go-sh
# gomodules.xyz/jsonpatch/v2 v2.4.0
Expand Down

0 comments on commit 0871891

Please sign in to comment.