Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

command/validate: respond to --help #9660

Merged
merged 1 commit into from
Oct 31, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions command/validate.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package command

import (
"flag"
"fmt"
"path/filepath"
"strings"

"github.com/hashicorp/terraform/config"
)
Expand All @@ -14,14 +16,16 @@ type ValidateCommand struct {

const defaultPath = "."

func (c *ValidateCommand) Help() string {
return ""
}

func (c *ValidateCommand) Run(args []string) int {
args = c.Meta.process(args, false)
var dirPath string

cmdFlags := flag.NewFlagSet("validate", flag.ContinueOnError)
cmdFlags.Usage = func() { c.Ui.Error(c.Help()) }
if err := cmdFlags.Parse(args); err != nil {
return 1
}

if len(args) == 1 {
dirPath = args[0]
} else {
Expand All @@ -42,6 +46,25 @@ func (c *ValidateCommand) Synopsis() string {
return "Validates the Terraform files"
}

func (c *ValidateCommand) Help() string {
helpText := `
Usage: terraform validate [options] [path]

Reads the Terraform files in the given path (directory) and
validates their syntax and basic semantics.

This is not a full validation that is normally done with
a plan or apply operation, but can be used to verify the basic
syntax and usage of Terraform configurations is correct.

Options:

-no-color If specified, output won't contain any color.

`
return strings.TrimSpace(helpText)
}

func (c *ValidateCommand) validate(dir string) int {
cfg, err := config.LoadDir(dir)
if err != nil {
Expand Down