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

Add flag to select the kibana version in elastic-package status #590

Merged
merged 3 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 16 additions & 12 deletions cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func setupStatusCommand() *cobraext.Command {
RunE: statusCommandAction,
}
cmd.Flags().BoolP(cobraext.ShowAllFlagName, "a", false, cobraext.ShowAllFlagDescription)
cmd.Flags().String(cobraext.StackVersionFlagName, "", cobraext.StackVersionFlagDescription)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This flag might be misleading here. In elastic-package status apache --version 8.0.0 the version flag may suggest that this is Apache 8.0.0, not Kibana.

What do you think about replacing it with --kibana-version?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or kibana.version? Thinking of it as the filters you can apply on epr, for example https://epr.elastic.co/search?experimental=true&kibana.version=8.0.0 It would become a more generic feature ...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that --kibana-version will look more like a command option. I haven't seen options with dots, I guess it's a standard?

But calling for a query is also an option: --query="kibana.version=8.0.0".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW do we really need the experimental flag? It's always enabled...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used --version because it is the flag used to specify the stack version in the stack subcomand, but I see how it can be confusing here.

I have opted for --kibana-version, I also prefer it to the version with the dot. How the kibana version is finally encoded in the query is an implementation detail.

But calling for a query is also an option: --query="kibana.version=8.0.0".

--kibana-version covers a very specific use case, so I prefer to have a specific flag for that. Also, package developers don't need to know the registry API to use this command, so I don't think we need generic options by now.

Humans needing to write url query parameters is a call for problems.

I haven't seen options with dots, I guess it's a standard?

This is not very common, but I am pretty sure it is possible to have options with dots, take a look to metricbeat --help 🙂

BTW do we really need the experimental flag? It's always enabled...

I hope we can get rid of this soon elastic/package-spec#225 🔥

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adjusting this!


return cobraext.NewCommand(cmd, cobraext.ContextPackage)
}
Expand All @@ -51,20 +52,27 @@ func statusCommandAction(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
packageName = args[0]
}
packageStatus, err := getPackageStatus(packageName, showAll)

kibanaVersion, err := cmd.Flags().GetString(cobraext.StackVersionFlagName)
if err != nil {
return cobraext.FlagParsingError(err, cobraext.StackVersionFlagName)
}
options := registry.SearchOptions{
All: showAll,
KibanaVersion: kibanaVersion,
}
packageStatus, err := getPackageStatus(packageName, options)
if err != nil {
return err
}
return print(packageStatus, os.Stdout)
}

func getPackageStatus(packageName string, showAll bool) (*status.PackageStatus, error) {
func getPackageStatus(packageName string, options registry.SearchOptions) (*status.PackageStatus, error) {
options.Internal = true
options.Experimental = true
if packageName != "" {
return status.RemotePackage(packageName, registry.SearchOptions{
All: showAll,
Internal: true,
Experimental: true,
})
return status.RemotePackage(packageName, options)
}
packageRootPath, found, err := packages.FindPackageRoot()
if !found {
Expand All @@ -73,11 +81,7 @@ func getPackageStatus(packageName string, showAll bool) (*status.PackageStatus,
if err != nil {
return nil, errors.Wrap(err, "locating package root failed")
}
return status.LocalPackage(packageRootPath, registry.SearchOptions{
All: showAll,
Internal: true,
Experimental: true,
})
return status.LocalPackage(packageRootPath, options)
}

// print formats and prints package information into a table
Expand Down
7 changes: 4 additions & 3 deletions internal/registry/revisions.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import (

// SearchOptions specify the query parameters without the package name for the search API
type SearchOptions struct {
Internal bool `url:"internal"`
Experimental bool `url:"experimental"`
All bool `url:"all"`
Internal bool `url:"internal"`
Experimental bool `url:"experimental"`
All bool `url:"all"`
KibanaVersion string `url:"kibana.version,omitempty"`
}

// searchQuery specify the package and query parameters for the search API
Expand Down