Skip to content

Commit e48fd4a

Browse files
committed
add --toml flag to print full Gopkg.toml
1 parent dc75adc commit e48fd4a

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

commands/operator-sdk/cmd/print_deps.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"github.com/spf13/cobra"
2222
)
2323

24+
var toml bool
25+
2426
func NewPrintDepsCmd() *cobra.Command {
2527
printDepsCmd := &cobra.Command{
2628
Use: "print-deps",
@@ -31,14 +33,20 @@ in an operators' Gopkg.toml file.`,
3133
Run: printDepsFunc,
3234
}
3335

36+
printDepsCmd.Flags().BoolVar(&toml, "toml", false, "Print dependencies in Gopkg.toml format.")
37+
3438
return printDepsCmd
3539
}
3640

3741
func printDepsFunc(cmd *cobra.Command, args []string) {
3842
if len(args) != 0 {
3943
log.Fatal("print-deps command does not take any arguments")
4044
}
41-
if err := scaffold.PrintGopkgDeps(); err != nil {
42-
log.Fatalf("print deps: (%v)", err)
45+
if toml {
46+
scaffold.PrintGopkgToml()
47+
} else {
48+
if err := scaffold.PrintGopkgDeps(); err != nil {
49+
log.Fatalf("print deps: (%v)", err)
50+
}
4351
}
4452
}

pkg/scaffold/gopkgtoml.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ required = [
9797
non-go = false
9898
`
9999

100+
func PrintGopkgToml() {
101+
fmt.Println(gopkgTomlTmpl)
102+
}
103+
100104
func PrintGopkgDeps() error {
101105
gopkgData := make(map[string]interface{})
102106
_, err := toml.Decode(gopkgTomlTmpl, &gopkgData)

0 commit comments

Comments
 (0)