Skip to content

Commit

Permalink
Add metadata functions command skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
dbanck committed Jan 16, 2023
1 parent 4fd8322 commit d63e319
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
6 changes: 6 additions & 0 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ func initCommands(
}, nil
},

"metadata functions": func() (cli.Command, error) {
return &command.MetadataFunctionsCommand{
Meta: meta,
}, nil
},

"output": func() (cli.Command, error) {
return &command.OutputCommand{
Meta: meta,
Expand Down
47 changes: 47 additions & 0 deletions internal/command/metadata_functions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package command

import (
"fmt"
)

// MetadataFunctionsCommand is a Command implementation that prints out information
// about the available functions in Terraform.
type MetadataFunctionsCommand struct {
Meta
}

func (c *MetadataFunctionsCommand) Help() string {
return metadataFunctionsCommandHelp
}

func (c *MetadataFunctionsCommand) Synopsis() string {
return "Show signatures and descriptions for the available functions"
}

func (c *MetadataFunctionsCommand) Run(args []string) int {
args = c.Meta.process(args)
cmdFlags := c.Meta.defaultFlagSet("metadata functions")
var jsonOutput bool
cmdFlags.BoolVar(&jsonOutput, "json", false, "produce JSON output")

cmdFlags.Usage = func() { c.Ui.Error(c.Help()) }
if err := cmdFlags.Parse(args); err != nil {
c.Ui.Error(fmt.Sprintf("Error parsing command-line flags: %s\n", err.Error()))
return 1
}

if !jsonOutput {
c.Ui.Error(
"The `terraform metadata functions` command requires the `-json` flag.\n")
cmdFlags.Usage()
return 1
}

return 0
}

const metadataFunctionsCommandHelp = `
Usage: terraform [global options] metadata functions -json
Prints out a json representation of the available function signatures.
`

0 comments on commit d63e319

Please sign in to comment.