-
Notifications
You must be signed in to change notification settings - Fork 301
/
get_provider_name.go
53 lines (44 loc) · 1.17 KB
/
get_provider_name.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package helper
import (
"bytes"
"context"
"fmt"
"github.com/loft-sh/devpod/cmd/flags"
"github.com/loft-sh/devpod/pkg/provider"
"github.com/loft-sh/devpod/pkg/workspace"
"github.com/loft-sh/log"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
type GetProviderNameCmd struct {
*flags.GlobalFlags
}
// NewGetProviderNameCmd creates a new command
func NewGetProviderNameCmd(flags *flags.GlobalFlags) *cobra.Command {
cmd := &GetProviderNameCmd{
GlobalFlags: flags,
}
shellCmd := &cobra.Command{
Use: "get-provider-name",
Short: "Retrieves a provider name",
RunE: func(_ *cobra.Command, args []string) error {
return cmd.Run(context.Background(), args)
},
}
return shellCmd
}
func (cmd *GetProviderNameCmd) Run(ctx context.Context, args []string) error {
if len(args) != 1 {
return fmt.Errorf("provider is missing")
}
providerRaw, _, err := workspace.ResolveProvider(args[0], log.Default.ErrorStreamOnly())
if err != nil {
return errors.Wrap(err, "resolve provider")
}
providerConfig, err := provider.ParseProvider(bytes.NewReader(providerRaw))
if err != nil {
return errors.Wrap(err, "parse provider")
}
fmt.Print(providerConfig.Name)
return nil
}