Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: print-deps prints file of user's choice or by top-level file; remove --as-file #1819

Merged
merged 1 commit into from
Aug 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
## Unreleased

### Added

- The `operator-sdk olm-catalog gen-csv` command now produces indented JSON for the `alm-examples` annotation. ([#1793](https://github.com/operator-framework/operator-sdk/pull/1793))
- Added flag `--dep-manager` to command [`operator-sdk print-deps`](https://github.com/operator-framework/operator-sdk/blob/master/doc/sdk-cli-reference.md#print-deps) to specify the type of dependency manager file to print. The choice of dependency manager is inferred from top-level dependency manager files present if `--dep-manager` is not set. ([#1819](https://github.com/operator-framework/operator-sdk/pull/1819))

### Changed

### Deprecated

### Removed

- Removed flag `--as-file` from command [`operator-sdk print-deps`](https://github.com/operator-framework/operator-sdk/blob/master/doc/sdk-cli-reference.md#print-deps), which now only prints packages and versions in dependency manager file format. The choice of dependency manager type is set by `--dep-manager` or inferred from top-level dependency manager files present if `--dep-manager` is not set. ([#1819](https://github.com/operator-framework/operator-sdk/pull/1819))

### Bug Fixes

- Configure the repo path correctly in `operator-sdk add crd` and prevent the command from running outside of an operator project. ([#1660](https://github.com/operator-framework/operator-sdk/pull/1660))

## v0.10.0
Expand Down
1 change: 1 addition & 0 deletions cmd/operator-sdk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ var commandsToSkip = map[string]struct{}{
"help": struct{}{},
"completion": struct{}{},
"version": struct{}{},
"print-deps": struct{}{}, // Does not require this logic
}

func skipCheckForCmd(cmd *cobra.Command) (skip bool) {
Expand Down
37 changes: 20 additions & 17 deletions cmd/operator-sdk/printdeps/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/spf13/cobra"
)

var asFile bool
var depManager string

func NewCmd() *cobra.Command {
printDepsCmd := &cobra.Command{
Expand All @@ -35,14 +35,11 @@ func NewCmd() *cobra.Command {
by this version of the Operator SDK. Versions for these packages should match
those in an operators' go.mod or Gopkg.toml file, depending on the dependency
manager chosen when initializing or migrating a project.

print-deps prints in columnar format by default. Use the --as-file flag to
print in go.mod or Gopkg.toml file format.
`,
RunE: printDepsFunc,
}

printDepsCmd.Flags().BoolVar(&asFile, "as-file", false, "Print dependencies in go.mod or Gopkg.toml file format, depending on the dependency manager chosen when initializing or migrating a project")
printDepsCmd.Flags().StringVar(&depManager, "dep-manager", "", `Dependency manager file type to print (choices: "dep", "modules")`)

return printDepsCmd
}
Expand All @@ -51,17 +48,23 @@ func printDepsFunc(cmd *cobra.Command, args []string) error {
if len(args) != 0 {
return fmt.Errorf("command %s doesn't accept any arguments", cmd.CommandPath())
}
projutil.MustInProjectRoot()

if err := printDeps(asFile); err != nil {
return fmt.Errorf("print deps failed: (%v)", err)
if err := printDeps(depManager); err != nil {
return fmt.Errorf("print deps failed: %v", err)
}
return nil
}

func printDeps(asFile bool) error {
// Make sure the project has a dep manager file.
mt, err := projutil.GetDepManagerType()
if err != nil {
func printDeps(depManager string) (err error) {
// Use depManager if set. Fall back to the project's current dep manager
// type if unset.
mt := projutil.DepManagerType(depManager)
if mt != "" {
if mt != projutil.DepManagerDep && mt != projutil.DepManagerGoMod {
return projutil.ErrInvalidDepManager(mt)
}
} else if mt, err = projutil.GetDepManagerType(); err != nil {
return err
}
isDep := mt == projutil.DepManagerDep
Expand All @@ -71,19 +74,19 @@ func printDeps(asFile bool) error {
switch {
case projutil.IsOperatorAnsible():
if isDep {
return ansible.PrintDepGopkgTOML(asFile)
return ansible.PrintDepGopkgTOML()
}
return ansible.PrintGoMod(asFile)
return ansible.PrintGoMod()
case projutil.IsOperatorHelm():
if isDep {
return helm.PrintDepGopkgTOML(asFile)
return helm.PrintDepGopkgTOML()
}
return helm.PrintGoMod(asFile)
return helm.PrintGoMod()
case projutil.IsOperatorGo():
if isDep {
return scaffold.PrintDepGopkgTOML(asFile)
return scaffold.PrintDepGopkgTOML()
}
return scaffold.PrintGoMod(asFile)
return scaffold.PrintGoMod()
}

return projutil.ErrUnknownOperatorType{}
Expand Down
8 changes: 4 additions & 4 deletions doc/sdk-cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ Prints the most recent Golang packages and versions required by operators. Print

### Flags

* `--as-file` - Print packages and versions in go.mod or Gopkg.toml format, depending on the dependency manager chosen when initializing or migrating a project.
* `--dep-manager` string - Dependency manager file type to print (choices: "dep", "modules")

### Example

With dependency manager `dep`:

```console
$ operator-sdk print-deps --as-file
$ operator-sdk print-deps
required = [
"k8s.io/code-generator/cmd/deepcopy-gen",
"k8s.io/code-generator/cmd/conversion-gen",
Expand All @@ -115,10 +115,10 @@ required = [
...
```

With dependency manager `modules`, i.e. go mod:
With dependency manager Go `modules`:

```console
$ operator-sdk print-deps --as-file
$ operator-sdk print-deps
module github.com/example-inc/memcached-operator

require (
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
contrib.go.opencensus.io/exporter/ocagent v0.4.11 // indirect
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
github.com/Azure/go-autorest v11.7.0+incompatible // indirect
github.com/BurntSushi/toml v0.3.1
github.com/MakeNowJust/heredoc v0.0.0-20171113091838-e9091a26100e // indirect
github.com/Masterminds/goutils v1.1.0 // indirect
github.com/Masterminds/semver v1.4.2 // indirect
Expand Down
9 changes: 3 additions & 6 deletions internal/pkg/scaffold/ansible/go_mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,11 @@ replace (
)
`

func PrintGoMod(asFile bool) error {
func PrintGoMod() error {
b, err := deps.ExecGoModTmpl(goModTmpl)
if err != nil {
return err
}
if asFile {
fmt.Print(string(b))
return nil
}
return deps.PrintGoMod(b)
fmt.Print(string(b))
return nil
}
10 changes: 3 additions & 7 deletions internal/pkg/scaffold/ansible/gopkgtoml.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (

"github.com/operator-framework/operator-sdk/internal/pkg/scaffold"
"github.com/operator-framework/operator-sdk/internal/pkg/scaffold/input"
"github.com/operator-framework/operator-sdk/internal/pkg/scaffold/internal/deps"
)

// GopkgToml - the Gopkg.toml file for a hybrid operator
Expand Down Expand Up @@ -58,10 +57,7 @@ const gopkgTomlTmpl = `[[constraint]]
unused-packages = true
`

func PrintDepGopkgTOML(asFile bool) error {
if asFile {
_, err := fmt.Println(gopkgTomlTmpl)
return err
}
return deps.PrintDepGopkgTOML(gopkgTomlTmpl)
func PrintDepGopkgTOML() error {
_, err := fmt.Println(gopkgTomlTmpl)
return err
}
9 changes: 3 additions & 6 deletions internal/pkg/scaffold/go_mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,11 @@ replace (
)
`

func PrintGoMod(asFile bool) error {
func PrintGoMod() error {
b, err := deps.ExecGoModTmpl(goModTmpl)
if err != nil {
return err
}
if asFile {
fmt.Print(string(b))
return nil
}
return deps.PrintGoMod(b)
fmt.Print(string(b))
return nil
}
11 changes: 3 additions & 8 deletions internal/pkg/scaffold/gopkgtoml.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"fmt"

"github.com/operator-framework/operator-sdk/internal/pkg/scaffold/input"
"github.com/operator-framework/operator-sdk/internal/pkg/scaffold/internal/deps"
)

const GopkgTomlFile = "Gopkg.toml"
Expand Down Expand Up @@ -93,13 +92,9 @@ required = [
[[prune.project]]
name = "k8s.io/kube-state-metrics"
unused-packages = true

`

func PrintDepGopkgTOML(asFile bool) error {
if asFile {
_, err := fmt.Println(gopkgTomlTmpl)
return err
}
return deps.PrintDepGopkgTOML(gopkgTomlTmpl)
func PrintDepGopkgTOML() error {
_, err := fmt.Println(gopkgTomlTmpl)
return err
}
9 changes: 3 additions & 6 deletions internal/pkg/scaffold/helm/go_mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,11 @@ replace (
)
`

func PrintGoMod(asFile bool) error {
func PrintGoMod() error {
b, err := deps.ExecGoModTmpl(goModTmpl)
if err != nil {
return err
}
if asFile {
fmt.Print(string(b))
return nil
}
return deps.PrintGoMod(b)
fmt.Print(string(b))
return nil
}
10 changes: 3 additions & 7 deletions internal/pkg/scaffold/helm/gopkgtoml.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (

"github.com/operator-framework/operator-sdk/internal/pkg/scaffold"
"github.com/operator-framework/operator-sdk/internal/pkg/scaffold/input"
"github.com/operator-framework/operator-sdk/internal/pkg/scaffold/internal/deps"
)

// GopkgToml - the Gopkg.toml file for a hybrid operator
Expand Down Expand Up @@ -89,10 +88,7 @@ revision = "a9fbbdc8dd8794b20af358382ab780559bca589d"
unused-packages = true
`

func PrintDepGopkgTOML(asFile bool) error {
if asFile {
_, err := fmt.Println(gopkgTomlTmpl)
return err
}
return deps.PrintDepGopkgTOML(gopkgTomlTmpl)
func PrintDepGopkgTOML() error {
_, err := fmt.Println(gopkgTomlTmpl)
return err
}
99 changes: 0 additions & 99 deletions internal/pkg/scaffold/internal/deps/print_dep.go

This file was deleted.

Loading