Skip to content

Commit

Permalink
feat: add list-resources command
Browse files Browse the repository at this point in the history
  • Loading branch information
ekristen committed Feb 4, 2024
1 parent aec7060 commit 8c3f31f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/ekristen/azure-nuke/pkg/common"

_ "github.com/ekristen/azure-nuke/pkg/commands/list"
_ "github.com/ekristen/azure-nuke/pkg/commands/nuke"

_ "github.com/ekristen/azure-nuke/resources"
Expand Down
60 changes: 60 additions & 0 deletions pkg/commands/list/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package list

import (
"fmt"
"github.com/ekristen/azure-nuke/pkg/nuke"
"github.com/fatih/color"
"github.com/urfave/cli/v2"
"sort"

"github.com/ekristen/azure-nuke/pkg/commands/global"
"github.com/ekristen/azure-nuke/pkg/common"

"github.com/ekristen/libnuke/pkg/resource"

_ "github.com/ekristen/azure-nuke/resources"
)

func execute(c *cli.Context) error {
ls := resource.GetNames()

sort.Strings(ls)

for _, name := range ls {
reg := resource.GetRegistration(name)

if reg.AlternativeResource != "" {
color.New(color.Bold).Printf("%-55s\n", name)
color.New(color.Bold, color.FgYellow).Printf(" > %-55s", reg.AlternativeResource)
color.New(color.FgCyan).Printf("alternative resource\n")
} else {
color.New(color.Bold).Printf("%-55s", name)
c := color.FgGreen
if reg.Scope == nuke.Tenant {
c = color.FgHiGreen
} else if reg.Scope == nuke.Subscription {
c = color.FgHiBlue
} else if reg.Scope == nuke.ResourceGroup {
c = color.FgHiMagenta
} else {

}
color.New(c).Printf(fmt.Sprintf("%s\n", string(reg.Scope)))
}
}

return nil
}

func init() {
cmd := &cli.Command{
Name: "resource-types",
Aliases: []string{"list-resources"},
Usage: "list available resources to nuke",
Flags: global.Flags(),
Before: global.Before,
Action: execute,
}

common.RegisterCommand(cmd)
}

0 comments on commit 8c3f31f

Please # to comment.