Skip to content

Commit

Permalink
chore: move cli output code into shared library
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippHeuer committed Nov 25, 2024
1 parent 6d228fb commit 9bbbc03
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 219 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/cidverse/cidverseutils/ci v0.1.0
github.com/cidverse/cidverseutils/compress v0.1.1
github.com/cidverse/cidverseutils/containerruntime v0.1.0
github.com/cidverse/cidverseutils/core v0.0.0-20241124224616-d11c8afe3a26
github.com/cidverse/cidverseutils/filesystem v0.1.1
github.com/cidverse/cidverseutils/hash v0.1.0
github.com/cidverse/cidverseutils/network v0.1.0
Expand Down Expand Up @@ -47,7 +48,7 @@ require (
github.com/BurntSushi/toml v1.4.0 // indirect
github.com/Masterminds/semver/v3 v3.3.1 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/ProtonMail/go-crypto v1.1.2 // indirect
github.com/ProtonMail/go-crypto v1.1.3 // indirect
github.com/antlr4-go/antlr/v4 v4.13.1 // indirect
github.com/charlievieth/fastwalk v1.0.9 // indirect
github.com/cidverse/cidverseutils/exec v0.1.0 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ github.com/Masterminds/semver/v3 v3.3.1/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lpr
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/ProtonMail/go-crypto v1.1.2 h1:A7JbD57ThNqh7XjmHE+PXpQ3Dqt3BrSAC0AL0Go3KS0=
github.com/ProtonMail/go-crypto v1.1.2/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE=
github.com/ProtonMail/go-crypto v1.1.3 h1:nRBOetoydLeUb4nHajyO2bKqMLfWQ/ZPwkXqXxPxCFk=
github.com/ProtonMail/go-crypto v1.1.3/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE=
github.com/ProtonMail/gopenpgp/v3 v3.0.0 h1:lqsrNKFv0U4tRYRdaMA8qzh3TACaDTg3iJiv7MFFmuM=
github.com/ProtonMail/gopenpgp/v3 v3.0.0/go.mod h1:XXZYIzOSEtEhKCyDcq/xepg3zuANcL5amIjwF4XZbNg=
github.com/adrg/xdg v0.5.3 h1:xRnxJXne7+oWDatRhR1JLnvuccuIeCoBu2rtuLqQB78=
Expand All @@ -32,6 +32,8 @@ github.com/cidverse/cidverseutils/compress v0.1.1 h1:VKmDRRGc5rQlzhnJy+ul1yS7Ogq
github.com/cidverse/cidverseutils/compress v0.1.1/go.mod h1:Xga0FDD+hHizd9zH99+DrbqXTAsblYQVEolYiOCN/Ug=
github.com/cidverse/cidverseutils/containerruntime v0.1.0 h1:Jqv7/ughImvDL/Q/pTei4m2tZskG4hXTLTfK/byLIY4=
github.com/cidverse/cidverseutils/containerruntime v0.1.0/go.mod h1:dyoA0ZzJc8YeTbZDtDnEFBXOuRXpOrQd5/9Y3XnZ3fg=
github.com/cidverse/cidverseutils/core v0.0.0-20241124224616-d11c8afe3a26 h1:w63E7MCxJYgpH+ysmYFPYV5KtY4YDGvea+cV4ZH+Di8=
github.com/cidverse/cidverseutils/core v0.0.0-20241124224616-d11c8afe3a26/go.mod h1:ce0txxfVVA+69HYQGpedk2W2TwRdsoLT5NFfZU8uuoI=
github.com/cidverse/cidverseutils/exec v0.1.0 h1:KbCnDISptCrFJFHDrA9efNM0GWNLVkon3yEzehisETY=
github.com/cidverse/cidverseutils/exec v0.1.0/go.mod h1:pBST2lLq7AnIZ6xM0foiz1VSUamGswN1csT/2MJAHHI=
github.com/cidverse/cidverseutils/filesystem v0.1.1 h1:xKGk+QhoywNKUp0artHkRPPOl+C3aa6wujkHhjTB6sI=
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/cidverse/cid/pkg/common/workflowrun"
"github.com/cidverse/cid/pkg/context"
"github.com/cidverse/cid/pkg/core/catalog"
"github.com/cidverse/cid/pkg/core/cmdoutput"
"github.com/cidverse/cid/pkg/core/rules"
"github.com/cidverse/cidverseutils/core/clioutputwriter"
"github.com/cidverse/cidverseutils/redact"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -50,7 +50,7 @@ func actionListCmd() *cobra.Command {
}

// data
data := cmdoutput.TabularData{
data := clioutputwriter.TabularData{
Headers: []string{"REPOSITORY", "ACTION", "TYPE", "SCOPE", "RULES", "DESCRIPTION"},
Rows: [][]interface{}{},
}
Expand All @@ -72,7 +72,7 @@ func actionListCmd() *cobra.Command {

// print
writer := redact.NewProtectedWriter(nil, os.Stdout, &sync.Mutex{}, nil)
err = cmdoutput.PrintData(writer, data, cmdoutput.Format(format))
err = clioutputwriter.PrintData(writer, data, clioutputwriter.Format(format))
if err != nil {
log.Fatal().Err(err).Msg("failed to print data")
os.Exit(1)
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"sync"

"github.com/cidverse/cid/pkg/core/catalog"
"github.com/cidverse/cid/pkg/core/cmdoutput"
"github.com/cidverse/cidverseutils/core/clioutputwriter"
"github.com/cidverse/cidverseutils/redact"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -54,7 +54,7 @@ func catalogListCmd() *cobra.Command {
registries := catalog.LoadSources()

// data
data := cmdoutput.TabularData{
data := clioutputwriter.TabularData{
Headers: []string{"NAME", "URI", "ADDED", "UPDATED", "WORKFLOWS", "ACTIONS", "IMAGES", "HASH"},
Rows: [][]interface{}{},
}
Expand All @@ -74,7 +74,7 @@ func catalogListCmd() *cobra.Command {

// print
writer := redact.NewProtectedWriter(nil, os.Stdout, &sync.Mutex{}, nil)
err := cmdoutput.PrintData(writer, data, cmdoutput.Format(format))
err := clioutputwriter.PrintData(writer, data, clioutputwriter.Format(format))
if err != nil {
log.Fatal().Err(err).Msg("failed to print data")
os.Exit(1)
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"sync"

"github.com/cidverse/cid/pkg/context"
"github.com/cidverse/cid/pkg/core/cmdoutput"
"github.com/cidverse/cidverseutils/core/clioutputwriter"
"github.com/cidverse/cidverseutils/redact"
"github.com/cidverse/repoanalyzer/analyzer"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -49,7 +49,7 @@ func moduleListCmd() *cobra.Command {
modules := analyzer.ScanDirectory(cid.ProjectDir)

// data
data := cmdoutput.TabularData{
data := clioutputwriter.TabularData{
Headers: []string{"NAME", "TYPE", "BUILD-SYSTEM", "BUILD-SYNTAX", "SPEC-TYPE", "SUBMODULES"},
Rows: [][]interface{}{},
}
Expand All @@ -66,7 +66,7 @@ func moduleListCmd() *cobra.Command {

// print
writer := redact.NewProtectedWriter(nil, os.Stdout, &sync.Mutex{}, nil)
err = cmdoutput.PrintData(writer, data, cmdoutput.Format(format))
err = clioutputwriter.PrintData(writer, data, clioutputwriter.Format(format))
if err != nil {
log.Fatal().Err(err).Msg("failed to print data")
os.Exit(1)
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"sync"

"github.com/cidverse/cid/pkg/context"
"github.com/cidverse/cid/pkg/core/cmdoutput"
"github.com/cidverse/cid/pkg/core/rules"
"github.com/cidverse/cidverseutils/core/clioutputwriter"
"github.com/cidverse/cidverseutils/redact"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -46,7 +46,7 @@ func stageListCmd() *cobra.Command {
}

// data
data := cmdoutput.TabularData{
data := clioutputwriter.TabularData{
Headers: []string{"WORKFLOW", "STAGE", "RULES", "ACTIONS"},
Rows: [][]interface{}{},
}
Expand All @@ -67,7 +67,7 @@ func stageListCmd() *cobra.Command {

// print
writer := redact.NewProtectedWriter(nil, os.Stdout, &sync.Mutex{}, nil)
err = cmdoutput.PrintData(writer, data, cmdoutput.Format(format))
err = clioutputwriter.PrintData(writer, data, clioutputwriter.Format(format))
if err != nil {
log.Fatal().Err(err).Msg("failed to print data")
os.Exit(1)
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

"github.com/cidverse/cid/pkg/context"
"github.com/cidverse/cid/pkg/core/catalog"
"github.com/cidverse/cid/pkg/core/cmdoutput"
"github.com/cidverse/cid/pkg/core/provenance"
"github.com/cidverse/cidverseutils/core/clioutputwriter"
"github.com/cidverse/cidverseutils/redact"

"github.com/cidverse/cid/pkg/common/workflowrun"
Expand Down Expand Up @@ -52,7 +52,7 @@ func workflowListCmd() *cobra.Command {
}

// data
data := cmdoutput.TabularData{
data := clioutputwriter.TabularData{
Headers: []string{"WORKFLOW", "VERSION", "RULES", "STAGES", "ACTIONS"},
Rows: [][]interface{}{},
}
Expand All @@ -68,7 +68,7 @@ func workflowListCmd() *cobra.Command {

// print
writer := redact.NewProtectedWriter(nil, os.Stdout, &sync.Mutex{}, nil)
err = cmdoutput.PrintData(writer, data, cmdoutput.Format(format))
err = clioutputwriter.PrintData(writer, data, clioutputwriter.Format(format))
if err != nil {
log.Fatal().Err(err).Msg("failed to print data")
os.Exit(1)
Expand Down
105 changes: 0 additions & 105 deletions pkg/core/cmdoutput/printoutput.go

This file was deleted.

96 changes: 0 additions & 96 deletions pkg/core/cmdoutput/printoutput_test.go

This file was deleted.

18 changes: 18 additions & 0 deletions pkg/core/config/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package config

import (
"testing"

"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
)

func TestEmbeddedConfigValid(t *testing.T) {
cfg := CIDConfig{}

err := yaml.Unmarshal([]byte(getEmbeddedConfig("files/cid-main.yaml")), &cfg)
assert.NoError(t, err)

err = yaml.Unmarshal([]byte(getEmbeddedConfig("files/cid-tools.yaml")), &cfg)
assert.NoError(t, err)
}

0 comments on commit 9bbbc03

Please sign in to comment.