Skip to content

Commit

Permalink
Main cli refactored without cobra
Browse files Browse the repository at this point in the history
  • Loading branch information
CDimonaco committed Jan 8, 2025
1 parent 57342dc commit 610cc05
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 117 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ default: clean mod-tidy fmt vet-check test build
.PHONY: build
build: workbench
workbench:
$(GO_BUILD) -o workbench
$(GO_BUILD) -o workbench cmd/workbench.go

.PHONY: cross-compiled $(ARCHS)
cross-compiled: $(ARCHS)
$(ARCHS):
@mkdir -p build/$@
GOOS=linux GOARCH=$@ $(GO_BUILD) -o build/$@/workbench
GOOS=linux GOARCH=$@ $(GO_BUILD) -o build/$@/workbench cmd/workbench.go

.PHONY: clean
clean: clean-binary
Expand Down
64 changes: 0 additions & 64 deletions cmd/execute.go

This file was deleted.

28 changes: 0 additions & 28 deletions cmd/root.go

This file was deleted.

71 changes: 71 additions & 0 deletions cmd/workbench.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package main

import (
"context"
"encoding/json"
"os"

"github.com/sirupsen/logrus"

"github.com/jessevdk/go-flags"
"github.com/trento-project/workbench/pkg/operator"
)

type opts struct {
Arguments string `long:"arguments" short:"a" description:"Json arguments of an operator" required:"true"`
Verbose bool `long:"verbose" short:"v" description:"Log verbosity"`
}

func main() {
ctx := context.Background()

var opts opts
_, err := flags.Parse(&opts)

Check failure on line 23 in cmd/workbench.go

View workflow job for this annotation

GitHub Actions / static-analysis

undefined: flags (typecheck)
if err != nil {
os.Exit(1)
}

logger := logrus.StandardLogger()
if opts.Verbose {
logger.SetLevel(logrus.DebugLevel)
}

operatorName := os.Args[1]

registry := operator.StandardRegistry(operator.WithCustomLogger(logger))

builder, err := registry.GetOperatorBuilder(operatorName)
if err != nil {
logger.Fatalf("operator: %s not available, exiting", operatorName)
}

opArgs := make(operator.OperatorArguments)
err = json.Unmarshal([]byte(opts.Arguments), &opArgs)
if err != nil {
logger.Fatalf("could not unmarhsal %s into arguments", opts.Arguments)
}

logger.Infof(
"starting execution with operator: %s - arguments: %s",
operatorName,
opts.Arguments,
)

op := builder("test-cli", opArgs)

report := op.Run(ctx)
if report.Error != nil {
logger.Fatalf(
"operation execution error, phase: %s, reason: %s",
report.Error.ErrorPhase,
report.Error.Message,
)
}

logger.Infof(
"execution succeded in phase: %s, diff: before: %s, after: %s",
report.Success.LastPhase,
report.Success.Diff["before"],
report.Success.Diff["after"],
)
}
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@ module github.com/trento-project/workbench
go 1.23.4

require (
github.com/jessevdk/go-flags v1.6.1
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.1
github.com/tidwall/gjson v1.18.0
golang.org/x/mod v0.21.0
)

require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/sys v0.29.0 // indirect
)
14 changes: 4 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jessevdk/go-flags v1.6.1 h1:Cvu5U8UGrLay1rZfv/zP7iLpSHGUZ/Ou68T0iX1bBK4=
github.com/jessevdk/go-flags v1.6.1/go.mod h1:Mk8T1hIAWpOiJiHa9rJASDK2UGWji0EuPGBnNLMooyc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
Expand All @@ -27,8 +21,8 @@ github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhso
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
9 changes: 0 additions & 9 deletions main.go

This file was deleted.

0 comments on commit 610cc05

Please sign in to comment.