Skip to content
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
71 changes: 71 additions & 0 deletions cmd/machine/inspect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package machine

import (
"context"
"encoding/json"
"fmt"

"github.com/loft-sh/devpod/cmd/flags"
"github.com/loft-sh/devpod/pkg/config"
"github.com/loft-sh/devpod/pkg/provider"
"github.com/loft-sh/devpod/pkg/workspace"
"github.com/loft-sh/log"
"github.com/spf13/cobra"
)

type InspectCmd struct {
*flags.GlobalFlags
}

func NewInspectCmd(flags *flags.GlobalFlags) *cobra.Command {
cmd := &InspectCmd{
GlobalFlags: flags,
}
stopCmd := &cobra.Command{
Use: "inspect",
Short: "Inspects an existing machine",
RunE: func(_ *cobra.Command, args []string) error {
return cmd.Run(context.Background(), args)
},
}

return stopCmd
}

func (cmd *InspectCmd) Run(ctx context.Context, args []string) error {
devPodConfig, err := config.LoadConfig(cmd.Context, cmd.Provider)
if err != nil {
return err
}

machineClient, err := workspace.GetMachine(devPodConfig, args, log.Default)
if err != nil {
return err
}
p, err := provider.LoadProviderConfig(devPodConfig.DefaultContext, machineClient.Provider())
if err != nil {
return err
}

machineConfig := machineClient.MachineConfig()
for k := range machineConfig.Provider.Options {
optConfig := p.Options[k]
if optConfig.Hidden {
delete(machineConfig.Provider.Options, k)
continue
}

if optConfig.Password {
opt := machineConfig.Provider.Options[k]
opt.Value = "********"
}
}

out, err := json.MarshalIndent(machineConfig, "", " ")
if err != nil {
return err
}
fmt.Println(string(out))

return nil
}
1 change: 1 addition & 0 deletions cmd/machine/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ func NewMachineCmd(flags *flags.GlobalFlags) *cobra.Command {
machineCmd.AddCommand(NewStatusCmd(flags))
machineCmd.AddCommand(NewDeleteCmd(flags))
machineCmd.AddCommand(NewCreateCmd(flags))
machineCmd.AddCommand(NewInspectCmd(flags))
return machineCmd
}