Skip to content

Commit

Permalink
add debug and quiet flags
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanking committed Jul 16, 2018
1 parent a29a393 commit c669d45
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
8 changes: 8 additions & 0 deletions cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ var applyCmd = &cobra.Command{
Short: "Apply model defined in fogg.json to the current tree.",
Long: "This command will take the model defined in fogg.json, build a plan and generate the appropriate files from templates.",
Run: func(cmd *cobra.Command, args []string) {
logLevel := log.InfoLevel
if debug { // debug overrides quiet
logLevel = log.DebugLevel
} else if quiet {
logLevel = log.FatalLevel
}
log.SetLevel(logLevel)

var e error
// Set up fs
pwd, e := os.Getwd()
Expand Down
9 changes: 8 additions & 1 deletion cmd/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@ var planCmd = &cobra.Command{
Short: "Run a plan",
Long: "plan will read fogg.json, use that to generate a plan and print that plan out. It will make no changes.",
Run: func(cmd *cobra.Command, args []string) {
logLevel := log.InfoLevel
if debug { // debug overrides quiet
logLevel = log.DebugLevel
} else if quiet {
logLevel = log.FatalLevel
}
log.SetLevel(logLevel)

var e error
// Set up fs

pwd, e := os.Getwd()
if e != nil {
log.Panic(e)
Expand Down
10 changes: 10 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ import (
"github.com/spf13/cobra"
)

var (
debug bool
quiet bool
)

func init() {
rootCmd.PersistentFlags().BoolVar(&debug, "debug", false, "enable verbose output")
rootCmd.PersistentFlags().BoolVarP(&quiet, "quiet", "q", false, "do not output to console; use return code to determine success/failure")
}

var rootCmd = &cobra.Command{
Use: "fogg",
Short: "",
Expand Down

0 comments on commit c669d45

Please sign in to comment.