-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from jedrekdomanski/machine-command
Add playground machines sub-command to labctl for listing machines in a playground
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package playground | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"text/tabwriter" | ||
"github.com/spf13/cobra" | ||
"github.com/iximiuz/labctl/internal/labcli" | ||
) | ||
|
||
func newMachinesCommand(cli labcli.CLI) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "machines [Playground ID]", | ||
Short: `List machines of a specific playground by Playground ID`, | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
playgroundID := args[0] | ||
return labcli.WrapStatusError(runListMachines(cmd.Context(), cli, playgroundID)) | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func runListMachines(ctx context.Context, cli labcli.CLI, playgroundID string) error { | ||
play, err := cli.Client().GetPlay(ctx, playgroundID) | ||
if err != nil { | ||
return fmt.Errorf("couldn't find playground with ID %s: %w", playgroundID, err) | ||
} | ||
|
||
writer := tabwriter.NewWriter(cli.OutputStream(), 0, 4, 2, ' ', 0) | ||
defer writer.Flush() | ||
|
||
fmt.Fprintln(writer, "MACHINE NAME") | ||
|
||
for _, machine := range play.Machines { | ||
fmt.Fprintln(writer, machine.Name) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters