From 386d5085cc0cf51f887334977c70417674685d5a Mon Sep 17 00:00:00 2001 From: Jeff Ortel Date: Tue, 19 Dec 2023 16:39:43 -0600 Subject: [PATCH] :sparkles: Add support for verbosity. (#68) Add support for verbosity. This mainly applies to reporting in task activity. When requested, the command output is included (live) in the activity log. This provides more detail and better insight into what the command is doing _currently_. Requires: - https://github.com/konveyor/tackle2-hub/pull/577 - https://github.com/konveyor/tackle2-addon/pull/50 --------- Signed-off-by: Jeff Ortel --- cmd/analyzer.go | 10 ++++++++-- cmd/main.go | 14 ++++++++++---- cmd/rules.go | 2 +- go.mod | 6 +++--- go.sum | 12 ++++++------ 5 files changed, 28 insertions(+), 16 deletions(-) diff --git a/cmd/analyzer.go b/cmd/analyzer.go index 76b0cf8..b621e5a 100644 --- a/cmd/analyzer.go +++ b/cmd/analyzer.go @@ -16,11 +16,14 @@ type Analyzer struct { // Run analyzer. func (r *Analyzer) Run() (b *builder.Issues, err error) { output := path.Join(Dir, "report.yaml") - cmd := command.Command{Path: "/usr/bin/konveyor-analyzer"} + cmd := command.New("/usr/bin/konveyor-analyzer") cmd.Options, err = r.options(output) if err != nil { return } + if Verbosity > 0 { + cmd.Reporter.Verbosity = command.LiveOutput + } b = &builder.Issues{Path: output} err = cmd.Run() return @@ -75,11 +78,14 @@ type DepAnalyzer struct { // Run analyzer. func (r *DepAnalyzer) Run() (b *builder.Deps, err error) { output := path.Join(Dir, "deps.yaml") - cmd := command.Command{Path: "/usr/bin/konveyor-analyzer-dep"} + cmd := command.New("/usr/bin/konveyor-analyzer-dep") cmd.Options, err = r.options(output) if err != nil { return } + if Verbosity > 0 { + cmd.Reporter.Verbosity = command.LiveOutput + } b = &builder.Deps{Path: output} err = cmd.Run() if err != nil { diff --git a/cmd/main.go b/cmd/main.go index d0e225a..6c548db 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -2,14 +2,15 @@ package main import ( "errors" + "os" + "path" + "time" + "github.com/gin-gonic/gin/binding" "github.com/konveyor/tackle2-addon/ssh" hub "github.com/konveyor/tackle2-hub/addon" "github.com/konveyor/tackle2-hub/api" "github.com/konveyor/tackle2-hub/nas" - "os" - "path" - "time" ) var ( @@ -21,6 +22,7 @@ var ( RuleDir = "" OptDir = "" Source = "Analysis" + Verbosity = 0 ) func init() { @@ -34,6 +36,8 @@ func init() { // Data Addon data passed in the secret. type Data struct { + // Verbosity level. + Verbosity int `json:"verbosity"` // Mode options. Mode Mode `json:"mode"` // Scope options. @@ -51,7 +55,9 @@ func main() { // Get the addon data associated with the task. d := &Data{} err = addon.DataWith(d) - if err != nil { + if err == nil { + Verbosity = d.Verbosity + } else { return } // diff --git a/cmd/rules.go b/cmd/rules.go index 999a9de..7eeb5cf 100644 --- a/cmd/rules.go +++ b/cmd/rules.go @@ -275,7 +275,7 @@ func (r *Rules) convert() (err error) { if err != nil { return } - cmd := command.Command{Path: "/usr/bin/windup-shim"} + cmd := command.New("/usr/bin/windup-shim") cmd.Options.Add("convert") cmd.Options.Add("--outputdir", output) cmd.Options.Add(RuleDir) diff --git a/go.mod b/go.mod index cb120f6..9fc56e0 100644 --- a/go.mod +++ b/go.mod @@ -5,8 +5,8 @@ go 1.18 require ( github.com/gin-gonic/gin v1.9.0 github.com/konveyor/analyzer-lsp v0.0.0-20230712145100-60dc2048444c - github.com/konveyor/tackle2-addon v0.3.0-beta.3.0.20231122051613-31d1afa8ce1c - github.com/konveyor/tackle2-hub v0.3.0-beta.2 + github.com/konveyor/tackle2-addon v0.3.0-rc.2.0.20231219212054-1119ca451542 + github.com/konveyor/tackle2-hub v0.3.0-rc.2.0.20231219211826-f09d0b24c0e6 github.com/onsi/gomega v1.27.6 github.com/rogpeppe/go-internal v1.10.0 go.lsp.dev/uri v0.3.0 @@ -57,7 +57,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 diff --git a/go.sum b/go.sum index 57cb299..516ba73 100644 --- a/go.sum +++ b/go.sum @@ -145,10 +145,10 @@ github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBF github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/konveyor/analyzer-lsp v0.0.0-20230712145100-60dc2048444c h1:DbOZO3cNmLBJ5Z6iXyl7Fb3ejWxicHAa3OHI++0KJd4= github.com/konveyor/analyzer-lsp v0.0.0-20230712145100-60dc2048444c/go.mod h1:+k6UreVv8ztI29/RyQN8/71AAmB0aWwQoWwZd3yR8sc= -github.com/konveyor/tackle2-addon v0.3.0-beta.3.0.20231122051613-31d1afa8ce1c h1:7lLxdzpFs/rwvLTm+saFrNz3Tqn6+/l5s2J01iRgGdA= -github.com/konveyor/tackle2-addon v0.3.0-beta.3.0.20231122051613-31d1afa8ce1c/go.mod h1:KQ1rdOjbrv8huxW7UnmojHGkdZLevOHpaQN9dcyZgfQ= -github.com/konveyor/tackle2-hub v0.3.0-beta.2 h1:1YTYX7ktHWmowNWElQtOzBldWflZe81Z89nxYMVRFzM= -github.com/konveyor/tackle2-hub v0.3.0-beta.2/go.mod h1:2ApwTxjVnIb3tP7XZKCEQdITsOgNHOeJ6qvchDsINFE= +github.com/konveyor/tackle2-addon v0.3.0-rc.2.0.20231219212054-1119ca451542 h1:Oywrm7FmnIensv4eP3E1UW2AeB0FfMi5Esoz6l54rRQ= +github.com/konveyor/tackle2-addon v0.3.0-rc.2.0.20231219212054-1119ca451542/go.mod h1:2ULCt88EGBK/N8bOCaerrUNlRw/VCZVXfXRBwmngNj4= +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.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= @@ -157,8 +157,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.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=