Skip to content

Commit

Permalink
add cmd
Browse files Browse the repository at this point in the history
refs #203
  • Loading branch information
fujiwara committed Sep 3, 2024
1 parent e4d0ed4 commit 4e3cc19
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cmd/tfstate-lookup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func _main() error {
defaultStateFile = DefaultStateFiles[0]
interactive bool
runJid bool
dump bool
timeout time.Duration
)
for _, name := range DefaultStateFiles {
Expand All @@ -47,6 +48,7 @@ func _main() error {
flag.StringVar(&stateLoc, "s", defaultStateFile, "tfstate file path or URL")
flag.BoolVar(&interactive, "i", false, "interactive mode")
flag.BoolVar(&runJid, "j", false, "run jid after selecting an item")
flag.BoolVar(&dump, "dump", false, "dump all resources")
flag.DurationVar(&timeout, "timeout", 0, "timeout for reading tfstate")
flag.Parse()

Expand All @@ -65,6 +67,9 @@ func _main() error {
if len(flag.Args()) > 0 {
key = flag.Arg(0)
} else {
if dump {
return dumpObjects(state)
}
// list
names, err := state.List()
if err != nil {
Expand All @@ -91,6 +96,16 @@ func _main() error {
}
}

func dumpObjects(state *tfstate.TFState) error {
res, err := state.Dump()
if err != nil {
return err
}
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
return enc.Encode(res)
}

func printObject(obj *tfstate.Object) error {
b := obj.Bytes()
w := os.Stdout
Expand Down

0 comments on commit 4e3cc19

Please sign in to comment.