metadata.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. Copyright 2020 Docker Compose CLI authors
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package cmd
  14. import (
  15. "encoding/json"
  16. "fmt"
  17. "github.com/spf13/cobra"
  18. "github.com/docker/compose-cli/internal"
  19. )
  20. // BackendMetadata backend metadata
  21. // TODO import this from cli when merged & available in /docker/cli
  22. type BackendMetadata struct {
  23. Name string
  24. Version string
  25. }
  26. // MetadataCommand command to display version
  27. func MetadataCommand() *cobra.Command {
  28. cmd := &cobra.Command{
  29. Use: "backend-metadata",
  30. Short: "return CLI backend metadata",
  31. Args: cobra.MaximumNArgs(0),
  32. Hidden: true,
  33. RunE: func(cmd *cobra.Command, _ []string) error {
  34. metadata := BackendMetadata{
  35. Name: "Cloud integration",
  36. Version: internal.Version,
  37. }
  38. jsonMeta, err := json.Marshal(metadata)
  39. if err != nil {
  40. return err
  41. }
  42. fmt.Println(string(jsonMeta))
  43. return nil
  44. },
  45. }
  46. return cmd
  47. }