From f20d905a51b20284a05092d189bfb6c7a5291bf3 Mon Sep 17 00:00:00 2001 From: Ranjandas Date: Fri, 9 Aug 2024 13:40:50 +1000 Subject: [PATCH] Add instance IP address to list output This PR adds a new field to the list output that shows the IP address of the `lima0` interface. Also, reduced the field width as more fields are getting added. --- cmd/list.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/list.go b/cmd/list.go index 0cee5eb..3d0e364 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -29,18 +29,18 @@ func init() { rootCmd.AddCommand(listCmd) listCmd.Flags().StringVarP(&cluster.Name, "name", "n", "", "name of the cluster") - listCmd.Flags().BoolVarP(&header, "no-header", "", false, "skip the header from list output") + listCmd.Flags().BoolVarP(&noheader, "no-header", "", false, "skip the header from list output") } -var header bool +var noheader bool func listInstances(clusterName string) { vms := lima.ListInstances() - w := tabwriter.NewWriter(os.Stdout, 5, 3, 7, byte(' '), 0) + w := tabwriter.NewWriter(os.Stdout, 4, 8, 4, byte(' '), 0) - if !header { - fmt.Fprintln(w, "CLUSTER\tVM NAME\tSTATUS\tSCENARIO\tDISK(GB)\tMEMORY(GB)\tCPUS\tIMAGE") + if !noheader { + fmt.Fprintln(w, "CLUSTER\tVM NAME\tIP(lima0)\tSTATUS\tSCENARIO\tDISK(GB)\tMEMORY(GB)\tCPUS\tIMAGE") } for _, vm := range vms { @@ -51,7 +51,7 @@ func listInstances(clusterName string) { continue //skip printing the } } - fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%d\t%d\t%d\t%s\n", getClusterNameFromInstanceName(vm.Name), vm.Name, vm.Status, vm.GetScenarioNameFromEnv(), bytesToGiB(vm.Disk), bytesToGiB(vm.Memory), vm.Cpus, getImageLocation(vm.Config.Images)) + fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%s\n", getClusterNameFromInstanceName(vm.Name), vm.Name, vm.GetIPAddress(), vm.Status, vm.GetScenarioNameFromEnv(), bytesToGiB(vm.Disk), bytesToGiB(vm.Memory), vm.Cpus, getImageLocation(vm.Config.Images)) } } w.Flush()