login.go 805 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package login
  2. import (
  3. "github.com/pkg/errors"
  4. "github.com/spf13/cobra"
  5. "github.com/docker/api/client"
  6. apicontext "github.com/docker/api/context"
  7. )
  8. // Command returns the compose command with its child commands
  9. func Command() *cobra.Command {
  10. command := &cobra.Command{
  11. Short: "Cloud login for docker contexts",
  12. Use: "login",
  13. }
  14. command.AddCommand(
  15. azureLoginCommand(),
  16. )
  17. return command
  18. }
  19. func azureLoginCommand() *cobra.Command {
  20. azureLoginCmd := &cobra.Command{
  21. Use: "azure",
  22. RunE: func(cmd *cobra.Command, args []string) error {
  23. ctx := apicontext.WithCurrentContext(cmd.Context(), "aci")
  24. c, err := client.New(ctx)
  25. if err != nil {
  26. return errors.Wrap(err, "cannot connect to backend")
  27. }
  28. return c.CloudService().Login(ctx, nil)
  29. },
  30. }
  31. return azureLoginCmd
  32. }