-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add metadata functions command skeleton
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
` |