From 1119ca4515424a69dd940a6e1968b9d91631c370 Mon Sep 17 00:00:00 2001 From: Jeff Ortel Date: Tue, 19 Dec 2023 15:20:54 -0600 Subject: [PATCH] :sparkles: Command verbosity with task report files. (#50) Add command reporting verbosity. This is intended to better support troubleshooting. Mainly, the support for level=_LiveOutput_. This _streams_ command output to files attached to the task report. The output reporting is rate-limited using a _backoff_ algorithm. Add command `New` _constructor_ and update the repository package to use it. **Requires**: https://github.com/konveyor/tackle2-hub/pull/577 Example: ``` - '[CMD] Running: /usr/bin/konveyor-analyzer --provider-settings /addon/opt/settings.json --output-file /addon/report.yaml --no-dependency-rules --rules /addon/rules/rulesets/1/rules --rules /addon/rules/rulesets/24/rules --rules /addon/rules/rulesets/20/rules --label-selector konveyor.io/target=cloud-readiness --dep-label-selector !konveyor.io/dep-source=open-source' - '[CMD] /usr/bin/konveyor-analyzer succeeded.' - '[CMD] Running: /usr/bin/konveyor-analyzer-dep --provider-settings /addon/opt/settings.json --output-file /addon/deps.yaml' - '[CMD] /usr/bin/konveyor-analyzer-dep succeeded.' - 'Analysis reported. duration: 102.5784ms' - '[TAG] Tagging Application 4.' - Facts updated. - Done. attached: - id: 989 name: konveyor-analyzer.output activity: 44 - id: 991 name: konveyor-analyzer-dep.output activity: 50 ``` --------- Signed-off-by: Jeff Ortel --- command/cmd.go | 76 +++++++++++++------------ command/reporter.go | 116 +++++++++++++++++++++++++++++++++++++++ command/writer.go | 89 ++++++++++++++++++++++++++++++ go.mod | 16 +++--- go.sum | 32 +++++------ repository/git.go | 14 ++--- repository/maven.go | 2 +- repository/subversion.go | 10 ++-- ssh/ssh.go | 8 +-- 9 files changed, 287 insertions(+), 76 deletions(-) create mode 100644 command/reporter.go create mode 100644 command/writer.go diff --git a/command/cmd.go b/command/cmd.go index dfb47e0..a28eec0 100644 --- a/command/cmd.go +++ b/command/cmd.go @@ -8,22 +8,30 @@ import ( "context" "fmt" "os/exec" - "strings" hub "github.com/konveyor/tackle2-hub/addon" + "path" ) var ( addon = hub.Addon ) +// +// New returns a command. +func New(path string) (cmd *Command) { + cmd = &Command{Path: path} + return +} + // // Command execution. type Command struct { - Options Options - Path string - Dir string - Output []byte + Options Options + Path string + Dir string + Reporter Reporter + Writer Writer } // @@ -40,22 +48,31 @@ func (r *Command) Run() (err error) { // The command and output are both reported in // task Report.Activity. func (r *Command) RunWith(ctx context.Context) (err error) { - addon.Activity( - "[CMD] Running: %s %s", - r.Path, - strings.Join(r.Options, " ")) + r.Writer.reporter = &r.Reporter + output := path.Base(r.Path) + ".output" + r.Reporter.file, err = addon.File.Touch(output) + if err != nil { + return + } + r.Reporter.Run(r.Path, r.Options) + addon.Attach(r.Reporter.file) + defer func() { + r.Writer.End() + if err != nil { + r.Reporter.Error(r.Path, err, r.Writer.buffer) + } else { + r.Reporter.Succeeded(r.Path, r.Writer.buffer) + } + }() cmd := exec.CommandContext(ctx, r.Path, r.Options...) cmd.Dir = r.Dir - r.Output, err = cmd.CombinedOutput() + cmd.Stdout = &r.Writer + cmd.Stderr = &r.Writer + err = cmd.Start() if err != nil { - addon.Activity( - "[CMD] %s failed: %s.\n%s", - r.Path, - err.Error(), - string(r.Output)) - } else { - addon.Activity("[CMD] succeeded.") + return } + err = cmd.Wait() return } @@ -64,26 +81,15 @@ func (r *Command) RunWith(ctx context.Context) (err error) { // On error: The command (without arguments) and output are // reported in task Report.Activity func (r *Command) RunSilent() (err error) { - err = r.RunSilentWith(context.TODO()) + r.Reporter.Verbosity = Error + err = r.RunWith(context.TODO()) return } // -// RunSilentWith executes the command with context. -// On error: The command (without arguments) and output are -// reported in task Report.Activity -func (r *Command) RunSilentWith(ctx context.Context) (err error) { - cmd := exec.CommandContext(ctx, r.Path, r.Options...) - cmd.Dir = r.Dir - r.Output, err = cmd.CombinedOutput() - if err != nil { - addon.Activity( - "[CMD] %s failed: %s.\n%s", - r.Path, - err.Error(), - string(r.Output)) - } - return +// Output returns the command output. +func (r *Command) Output() (b []byte) { + return r.Writer.buffer } // @@ -91,14 +97,14 @@ func (r *Command) RunSilentWith(ctx context.Context) (err error) { type Options []string // -// add +// Add option. func (a *Options) Add(option string, s ...string) { *a = append(*a, option) *a = append(*a, s...) } // -// add +// Addf option. func (a *Options) Addf(option string, x ...interface{}) { *a = append(*a, fmt.Sprintf(option, x...)) } diff --git a/command/reporter.go b/command/reporter.go new file mode 100644 index 0000000..4c7656d --- /dev/null +++ b/command/reporter.go @@ -0,0 +1,116 @@ +package command + +import ( + "strings" + "github.com/konveyor/tackle2-hub/api" +) + +// +// Verbosity. +const ( + // Disabled reports: NOTHING. + Disabled = -2 + // Error reports: error. + Error = -1 + // Default reports: error, started, succeeded. + Default = 0 + // LiveOutput reports: error, started, succeeded, output (live). + LiveOutput = 1 +) + +// +// Reporter activity reporter. +type Reporter struct { + Verbosity int + file *api.File + index int +} + +// +// Run reports command started in task Report.Activity. +func (r *Reporter) Run(path string, options Options) { + switch r.Verbosity { + case Disabled: + case Error: + case Default, + LiveOutput: + addon.Activity( + "[CMD] Running: %s %s", + path, + strings.Join(options, " ")) + } +} + +// +// Succeeded reports command succeeded in task Report.Activity. +func (r *Reporter) Succeeded(path string, output []byte) { + switch r.Verbosity { + case Disabled: + case Error: + case Default: + addon.Activity( + "[CMD] %s succeeded.", + path) + r.append(output) + case LiveOutput: + addon.Activity( + "[CMD] %s succeeded.", + path) + } +} + +// +// Error reports command failed in task Report.Activity. +func (r *Reporter) Error(path string, err error, output []byte) { + if len(output) == 0 { + return + } + switch r.Verbosity { + case Disabled: + case Error, + Default: + addon.Activity( + "[CMD] %s failed: %s", + path, + err.Error()) + r.append(output) + case LiveOutput: + addon.Activity( + "[CMD] %s failed: %s.", + path, + err.Error()) + } +} + +// +// Output reports command output. +func (r *Reporter) Output(buffer []byte) (reported int) { + switch r.Verbosity { + case Disabled: + case Error: + case Default: + case LiveOutput: + if r.index >= len(buffer) { + return + } + batch := buffer[r.index:] + reported = len(batch) + if reported > 0 { + r.index += reported + r.append(batch) + } + } + return +} + +// +// append output. +func (r *Reporter) append(batch []byte) { + if r.file == nil { + return + } + err := addon.File.Patch(r.file.ID, batch) + if err != nil { + panic(err) + } +} diff --git a/command/writer.go b/command/writer.go new file mode 100644 index 0000000..208c28f --- /dev/null +++ b/command/writer.go @@ -0,0 +1,89 @@ +package command + +import ( + "time" +) + +const ( + // Backoff rate increment. + Backoff = time.Millisecond * 100 + // MaxBackoff max backoff. + MaxBackoff = 10 * Backoff + // MinBackoff minimum backoff. + MinBackoff = Backoff +) + +// +// Writer records command output. +type Writer struct { + reporter *Reporter + buffer []byte + backoff time.Duration + end chan any + ended chan any +} + +// +// Write command output. +func (w *Writer) Write(p []byte) (n int, err error) { + n = len(p) + w.buffer = append(w.buffer, p...) + switch w.reporter.Verbosity { + case LiveOutput: + if w.ended == nil { + w.end = make(chan any) + w.ended = make(chan any) + go w.report() + } + } + return +} + +// +// End of writing. +func (w *Writer) End() { + if w.end == nil { + return + } + close(w.end) + <-w.ended + close(w.ended) + w.end = nil +} + +// +// report in task Report.Activity. +// Rate limited. +func (w *Writer) report() { + w.backoff = MinBackoff + ended := false + for { + select { + case <-w.end: + ended = true + case <-time.After(w.backoff): + } + n := w.reporter.Output(w.buffer) + w.adjustBackoff(n) + if ended && n == 0 { + break + } + } + w.ended <- true +} + +// +// adjustBackoff adjust the backoff as needed. +// incremented when output reported. +// decremented when no outstanding output reported. +func (w *Writer) adjustBackoff(reported int) { + if reported > 0 { + if w.backoff < MaxBackoff { + w.backoff += Backoff + } + } else { + if w.backoff > MinBackoff { + w.backoff -= Backoff + } + } +} diff --git a/go.mod b/go.mod index de09f88..88bb51d 100644 --- a/go.mod +++ b/go.mod @@ -4,8 +4,8 @@ go 1.18 require ( github.com/clbanning/mxj v1.8.4 - github.com/jortel/go-utils v0.1.1 - github.com/konveyor/tackle2-hub v0.2.2-0.20230731153407-22bf2d68128a + github.com/jortel/go-utils v0.1.2 + github.com/konveyor/tackle2-hub v0.3.0-rc.2.0.20231219211826-f09d0b24c0e6 ) require ( @@ -43,7 +43,7 @@ require ( github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.0.9 // indirect - github.com/leodido/go-urn v1.2.3 // indirect + github.com/leodido/go-urn v1.2.4 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-isatty v0.0.17 // indirect github.com/mattn/go-sqlite3 v1.14.17 // indirect @@ -64,12 +64,12 @@ require ( github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.9 // indirect golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect - golang.org/x/crypto v0.7.0 // indirect - golang.org/x/net v0.8.0 // indirect + golang.org/x/crypto v0.14.0 // indirect + golang.org/x/net v0.17.0 // indirect golang.org/x/oauth2 v0.5.0 // indirect - golang.org/x/sys v0.7.0 // indirect - golang.org/x/term v0.6.0 // indirect - golang.org/x/text v0.8.0 // indirect + golang.org/x/sys v0.13.0 // indirect + golang.org/x/term v0.13.0 // indirect + golang.org/x/text v0.13.0 // indirect golang.org/x/time v0.3.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.30.0 // indirect diff --git a/go.sum b/go.sum index 21968df..6c61bae 100644 --- a/go.sum +++ b/go.sum @@ -111,8 +111,8 @@ github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkr github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= -github.com/jortel/go-utils v0.1.1 h1:zkAAA+i5Z+151zUG7lkjILGxSo3pQ4bkLTRcPTCy3hs= -github.com/jortel/go-utils v0.1.1/go.mod h1:sl6vav63ODI0sUfSz8e0pImNmCVFnVsuOFhZmwe9GDk= +github.com/jortel/go-utils v0.1.2 h1:R0TcGRCcwoL793CymcKC5AF9idWXT2cR6eQ2xpBUsoI= +github.com/jortel/go-utils v0.1.2/go.mod h1:sl6vav63ODI0sUfSz8e0pImNmCVFnVsuOFhZmwe9GDk= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= @@ -121,8 +121,8 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/konveyor/tackle2-hub v0.2.2-0.20230731153407-22bf2d68128a h1:HdMqKoiaBkWdEs2TQ0G8BN0HbsUeUhI8bhVdLEPini4= -github.com/konveyor/tackle2-hub v0.2.2-0.20230731153407-22bf2d68128a/go.mod h1:mxl0Sluwk5XpCWw8U+lvy6dpYu15LzgfU6So/8lwH6E= +github.com/konveyor/tackle2-hub v0.3.0-rc.2.0.20231219211826-f09d0b24c0e6 h1:xPLwmNqA3QxVaqqnhF6v/T2ZMTCom2GcROD2BEJIHnQ= +github.com/konveyor/tackle2-hub v0.3.0-rc.2.0.20231219211826-f09d0b24c0e6/go.mod h1:ZR4A0+Wp0H3QZkMohPnvZjxcolVORP3jdHV9Uwb/PoE= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= @@ -130,8 +130,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/leodido/go-urn v1.2.3 h1:6BE2vPT0lqoz3fmOesHZiaiFh7889ssCo2GMvLCfiuA= -github.com/leodido/go-urn v1.2.3/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= +github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= +github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= @@ -206,8 +206,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= -golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= @@ -226,8 +226,8 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= -golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.5.0 h1:HuArIo48skDwlrvM3sEdHXElYslAMsf3KwRkkW4MC4s= golang.org/x/oauth2 v0.5.0/go.mod h1:9/XBHVqLaWO3/BRHs5jbpYCnOZVjj5V0ndyaAM7KB4I= @@ -248,18 +248,18 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= -golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw= -golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= +golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek= +golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= -golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/repository/git.go b/repository/git.go index e9a1293..f1892eb 100644 --- a/repository/git.go +++ b/repository/git.go @@ -71,7 +71,7 @@ func (r *Git) Fetch() (err error) { if err != nil { return } - cmd := command.Command{Path: "/usr/bin/git"} + cmd := command.New("/usr/bin/git") cmd.Options.Add("clone", url.String(), r.Path) err = cmd.Run() if err != nil { @@ -83,12 +83,12 @@ func (r *Git) Fetch() (err error) { // Branch creates a branch with the given name if not exist and switch to it. func (r *Git) Branch(name string) (err error) { - cmd := command.Command{Path: "/usr/bin/git"} + cmd := command.New("/usr/bin/git") cmd.Dir = r.Path cmd.Options.Add("checkout", name) err = cmd.Run() if err != nil { - cmd = command.Command{Path: "/usr/bin/git"} + cmd = command.New("/usr/bin/git") cmd.Dir = r.Path cmd.Options.Add("checkout", "-b", name) } @@ -98,7 +98,7 @@ func (r *Git) Branch(name string) (err error) { // addFiles adds files to staging area. func (r *Git) addFiles(files []string) (err error) { - cmd := command.Command{Path: "/usr/bin/git"} + cmd := command.New("/usr/bin/git") cmd.Dir = r.Path cmd.Options.Add("add", files...) return cmd.Run() @@ -110,7 +110,7 @@ func (r *Git) Commit(files []string, msg string) (err error) { if err != nil { return err } - cmd := command.Command{Path: "/usr/bin/git"} + cmd := command.New("/usr/bin/git") cmd.Dir = r.Path cmd.Options.Add("commit") cmd.Options.Add("--message", msg) @@ -123,7 +123,7 @@ func (r *Git) Commit(files []string, msg string) (err error) { // push changes to remote. func (r *Git) push() (err error) { - cmd := command.Command{Path: "/usr/bin/git"} + cmd := command.New("/usr/bin/git") cmd.Dir = r.Path cmd.Options.Add("push", "--set-upstream", "origin", r.Remote.Branch) return cmd.Run() @@ -292,7 +292,7 @@ func (r *Git) checkout() (err error) { _ = os.Chdir(dir) }() _ = os.Chdir(r.Path) - cmd := command.Command{Path: "/usr/bin/git"} + cmd := command.New("/usr/bin/git") cmd.Options.Add("checkout", branch) err = cmd.Run() return diff --git a/repository/maven.go b/repository/maven.go index b427066..7ce51f0 100644 --- a/repository/maven.go +++ b/repository/maven.go @@ -178,7 +178,7 @@ func (r *Maven) run(options command.Options) (err error) { if err != nil { return } - cmd := command.Command{Path: "/usr/bin/mvn"} + cmd := command.New("/usr/bin/svn") cmd.Options = options cmd.Options.Addf("-DoutputDirectory=%s", r.BinDir) cmd.Options.Addf("-Dmaven.repo.local=%s", r.M2Dir) diff --git a/repository/subversion.go b/repository/subversion.go index 796c8f8..afbf115 100644 --- a/repository/subversion.go +++ b/repository/subversion.go @@ -81,7 +81,7 @@ func (r *Subversion) checkout(branch string) (err error) { if err != nil { return } - cmd := command.Command{Path: "/usr/bin/svn"} + cmd := command.New("/usr/bin/svn") cmd.Options.Add("--non-interactive") if insecure { cmd.Options.Add("--trust-server-cert") @@ -105,7 +105,7 @@ func (r *Subversion) Branch(name string) error { // createBranch creates a branch with the given name func (r *Subversion) createBranch(name string) (err error) { url := *r.URL() - cmd := command.Command{Path: "/usr/bin/svn"} + cmd := command.New("/usr/bin/svn") cmd.Options.Add("--non-interactive") branchUrl := url @@ -121,7 +121,7 @@ func (r *Subversion) createBranch(name string) (err error) { // addFiles adds files to staging area func (r *Subversion) addFiles(files []string) (err error) { - cmd := command.Command{Path: "/usr/bin/svn"} + cmd := command.New("/usr/bin/svn") cmd.Dir = r.Path cmd.Options.Add("add") cmd.Options.Add("--force", files...) @@ -135,7 +135,7 @@ func (r *Subversion) Commit(files []string, msg string) (err error) { if err != nil { return } - cmd := command.Command{Path: "/usr/bin/svn"} + cmd := command.New("/usr/bin/svn") cmd.Dir = r.Path cmd.Options.Add("commit", "-m", msg) err = cmd.Run() @@ -199,7 +199,7 @@ func (r *Subversion) writePassword(id *api.Identity) (err error) { return } - cmd := command.Command{Path: "/usr/bin/svn"} + cmd := command.New("/usr/bin/svn") cmd.Options.Add("--non-interactive") cmd.Options.Add("--username") cmd.Options.Add(id.User) diff --git a/ssh/ssh.go b/ssh/ssh.go index 2d543a2..a5b23be 100644 --- a/ssh/ssh.go +++ b/ssh/ssh.go @@ -38,7 +38,7 @@ type Agent struct { func (r *Agent) Start() (err error) { pid := os.Getpid() socket := fmt.Sprintf("/tmp/agent.%d", pid) - cmd := command.Command{Path: "/usr/bin/ssh-agent"} + cmd := command.New("/usr/bin/ssh-agent") cmd.Options.Add("-a", socket) err = cmd.Run() if err != nil { @@ -97,13 +97,13 @@ func (r *Agent) Add(id *api.Identity, host string) (err error) { context.TODO(), time.Second) defer fn() - cmd := command.Command{Path: "/usr/bin/ssh-add"} + cmd := command.New("/usr/bin/ssh-add") cmd.Options.Add(path) err = cmd.RunWith(ctx) if err != nil { return } - cmd = command.Command{Path: "/usr/bin/ssh-keyscan"} + cmd = command.New("/usr/bin/ssh-keyscan") cmd.Options.Add(host) err = cmd.Run() if err != nil { @@ -120,7 +120,7 @@ func (r *Agent) Add(id *api.Identity, host string) (err error) { path) return } - _, err = f.Write(cmd.Output) + _, err = f.Write(cmd.Output()) if err != nil { err = liberr.Wrap( err,