Skip to content

Commit

Permalink
Merge pull request #63 from ashmilhussain/master
Browse files Browse the repository at this point in the history
add filter for get commands
  • Loading branch information
anoopl authored Nov 28, 2019
2 parents 2ef5265 + f12f5c5 commit ac9abf1
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 26 deletions.
3 changes: 2 additions & 1 deletion cmd/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,11 @@ var getClusterCmd = &cobra.Command{
}

rgroupName := getViper.GetString("metadata.resource-group") // getting values through viper
clusterFilter, _ := cmd.Flags().GetString("flag")

color.Cyan("rgroupName : " + rgroupName)

cluster.GetCluster(rgroupName)
cluster.GetCluster(rgroupName, clusterFilter)
},
}

Expand Down
4 changes: 3 additions & 1 deletion cmd/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,11 @@ var getDiskCmd = &cobra.Command{
//getDiskViper.SetDefault("diskResourceGroup", "DiskRGDefault") // for setting a default value

diskResourceGroup := getDiskViper.GetString("managedDisk.resource-group")
diskFilter, _ := cmd.Flags().GetString("flag")

color.Cyan("diskResourceGroup : " + diskResourceGroup)

disk.GetDisk(diskResourceGroup)
disk.GetDisk(diskResourceGroup, diskFilter)
},
}

Expand Down Expand Up @@ -206,6 +207,7 @@ func init() {

getCmd.AddCommand(getDiskCmd)
getDiskCmd.PersistentFlags().StringP("rgroupname", "g", "opsFlagDefaultG", "disk resource group")
getDiskCmd.PersistentFlags().StringP("flag", "l", "all", "filtr flag")

getDiskViper.BindPFlag("managedDisk.resource-group", getDiskCmd.PersistentFlags().Lookup("rgroupname"))

Expand Down
4 changes: 3 additions & 1 deletion cmd/nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,11 @@ var getNodePoolCmd = &cobra.Command{
// getting values through viper
clusterName := getNPViper.GetString("nodePools.cluster-name")
rgroupName := getNPViper.GetString("nodePools.resource-group")
nodepoolFilter, _ := cmd.Flags().GetString("flag")

fmt.Println("clusterName : ", clusterName, ", ", "rgroupName : ", rgroupName)

nodepool.GetNodePool(clusterName, rgroupName)
nodepool.GetNodePool(clusterName, rgroupName, nodepoolFilter)
},
}

Expand Down Expand Up @@ -229,6 +230,7 @@ func init() {
getCmd.AddCommand(getNodePoolCmd)
getNodePoolCmd.PersistentFlags().StringP("rgroupname", "g", "rgFlag", "NodePool resource group")
getNodePoolCmd.PersistentFlags().StringP("clustername", "c", "clusterFlag", "NodePool cluster")
getNodePoolCmd.PersistentFlags().StringP("flag", "l", "all", "filtr flag")

getNPViper.BindPFlag("nodePools.cluster-name", getNodePoolCmd.PersistentFlags().Lookup("clustername"))
getNPViper.BindPFlag("nodePools.resource-group", getNodePoolCmd.PersistentFlags().Lookup("rgroupname"))
Expand Down
7 changes: 4 additions & 3 deletions cmd/resourcegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ var getResourceGroupCmd = &cobra.Command{
if err != nil { // Handle errors reading the config file
panic(fmt.Errorf("Fatal error config file: %s \n", err))
}

resourcegroup.GetResourceGroup()
rGroupFilter, _ := cmd.Flags().GetString("flag")
resourcegroup.GetResourceGroup(rGroupFilter)
},
}

Expand Down Expand Up @@ -166,7 +166,8 @@ func init() {

getCmd.AddCommand(getResourceGroupCmd)

getRGViper.BindPFlags(getCmd.PersistentFlags())
getResourceGroupCmd.PersistentFlags().StringP("flag", "l", "all", "filtr flag")
getRGViper.BindPFlags(getResourceGroupCmd.PersistentFlags())
// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
Expand Down
16 changes: 10 additions & 6 deletions pkg/ctl/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package cluster
import (
"bytes"
"fmt"
"os"
"os/exec"
"time"

"github.com/adfolks/aksctl/pkg/ctl/utils"
"github.com/fatih/color"
"github.com/gernest/wow"
"github.com/gernest/wow/spin"
"github.com/kyokomi/emoji"
"os"
"os/exec"
"time"
)

//CreateCluster creates a cluster
Expand Down Expand Up @@ -111,7 +112,7 @@ func UpdateCluster(clusterName string, resourceGroupName string) {
}

//GetCluster will list the available clusters
func GetCluster(resourceGroupName string) {
func GetCluster(resourceGroupName string, clusterFilter string) {
a := wow.New(os.Stdout, spin.Get(spin.Dots), "Collecting your k8s Cluster informations")
a.Start()
time.Sleep(2 * time.Second)
Expand All @@ -129,8 +130,11 @@ func GetCluster(resourceGroupName string) {
return
}
a.PersistWith(spin.Spinner{}, "....")
fmt.Println("Result: " + out.String())
fmt.Println("Type:", utils.FilterStringMap(out.String(), "name"))
if clusterFilter == "all" {
fmt.Println("Result: " + out.String())
} else {
fmt.Println("Result:", utils.FilterStringMap(out.String(), clusterFilter))
}

}

Expand Down
14 changes: 10 additions & 4 deletions pkg/ctl/disk/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import (
"fmt"
"os/exec"

"os"
"time"

"github.com/adfolks/aksctl/pkg/ctl/utils"
"github.com/fatih/color"
"github.com/gernest/wow"
"github.com/gernest/wow/spin"
"github.com/kyokomi/emoji"
"os"
"time"
)

//CreateDisk will create a disk
Expand Down Expand Up @@ -81,7 +83,7 @@ func UpdateDisk(diskName string, diskResourceGroup string, diskSize string) {
}

//GetDisk will list the available disks
func GetDisk(diskResourceGroup string) {
func GetDisk(diskResourceGroup string, diskFilter string) {
a := wow.New(os.Stdout, spin.Get(spin.Dots), "Fetching disks")
a.Start()
time.Sleep(2 * time.Second)
Expand All @@ -99,5 +101,9 @@ func GetDisk(diskResourceGroup string) {
return
}
a.PersistWith(spin.Spinner{}, "....")
fmt.Println("Result: " + out.String())
if diskFilter == "all" {
fmt.Println("Result: " + out.String())
} else {
fmt.Println("Result:", utils.FilterStringMap(out.String(), diskFilter))
}
}
16 changes: 11 additions & 5 deletions pkg/ctl/nodepool/nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package nodepool
import (
"bytes"
"fmt"
"os"
"os/exec"
"time"

"github.com/adfolks/aksctl/pkg/ctl/utils"
"github.com/fatih/color"
"github.com/gernest/wow"
"github.com/gernest/wow/spin"
"github.com/kyokomi/emoji"
"os"
"os/exec"
"time"
)

//CreateNodePool will create a nodepool
Expand Down Expand Up @@ -98,7 +100,7 @@ func UpdateNodePool(clusterName string, nodePoolName string, rgroupName string)
}

//GetNodePool will list the nodepools
func GetNodePool(clusterName string, rgroupName string) {
func GetNodePool(clusterName string, rgroupName string, nodepoolFilter string) {
a := wow.New(os.Stdout, spin.Get(spin.Dots), "Fetching nodepools")
a.Start()
time.Sleep(2 * time.Second)
Expand All @@ -114,5 +116,9 @@ func GetNodePool(clusterName string, rgroupName string) {
return
}
a.PersistWith(spin.Spinner{}, "....")
fmt.Println("Result: " + out.String())
if nodepoolFilter == "all" {
fmt.Println("Result: " + out.String())
} else {
fmt.Println("Result:", utils.FilterStringMap(out.String(), nodepoolFilter))
}
}
16 changes: 11 additions & 5 deletions pkg/ctl/resourcegroup/resourcegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package resourcegroup
import (
"bytes"
"fmt"
"os"
"os/exec"
"time"

"github.com/adfolks/aksctl/pkg/ctl/utils"
"github.com/fatih/color"
"github.com/gernest/wow"
"github.com/gernest/wow/spin"
"github.com/kyokomi/emoji"
"os"
"os/exec"
"time"
)

//CreateResourceGroup will create a resource group
Expand Down Expand Up @@ -100,7 +102,7 @@ func UpdateResourceGroup(rgroupName string) {
}

//GetResourceGroup will list the resource groups
func GetResourceGroup() {
func GetResourceGroup(filterRgroup string) {
a := wow.New(os.Stdout, spin.Get(spin.Dots), "Fetching resource groups")
a.Start()
time.Sleep(2 * time.Second)
Expand All @@ -117,5 +119,9 @@ func GetResourceGroup() {
return
}
a.PersistWith(spin.Spinner{}, "....")
fmt.Println("Result: " + out.String())
if filterRgroup == "all" {
fmt.Println("Result: " + out.String())
} else {
fmt.Println("Result:", utils.FilterStringMap(out.String(), filterRgroup))
}
}

0 comments on commit ac9abf1

Please sign in to comment.