package commands

import (
	"fmt"
	"github.com/spf13/cobra"
	"os"
)

var outCmd = &cobra.Command{
	Use:   "out",
	Short: "Write a file based on key data.",
	Long:  `out is for writing a file based on a Consul key.`,
	Run:   outRun,
}

func outRun(cmd *cobra.Command, args []string) {
	checkFlags()
}

func checkFlags() {
	if KeyLocation == "" {
		fmt.Println("Need a key location in -k")
		os.Exit(1)
	}
	if FiletoWrite == "" {
		fmt.Println("Need a file to write in -f")
		os.Exit(1)
	}
}

var KeyLocation string
var FiletoWrite string
var MinFileLength int

func init() {
	RootCmd.AddCommand(outCmd)
	outCmd.Flags().StringVarP(&KeyLocation, "key", "k", "", "key to pull data from")
	outCmd.Flags().StringVarP(&FiletoWrite, "file", "f", "", "where to write the data")
	outCmd.Flags().IntVarP(&MinFileLength, "length", "l", 10, "minimum amount of lines in the file")
}

package commands

import (
	"fmt"
	"github.com/spf13/cobra"
)

var outCmd = &cobra.Command{
	Use:   "out",
	Short: "Write a file based on key data.",
	Long:  `out is for writing a file based on a Consul key.`,
	Run:   outRun,
}

func outRun(cmd *cobra.Command, args []string) {
	checkFlags()
}

func checkFlags() {
	if KeyLocation == "" {
		fmt.Println("Need a key location in -k")
	}
	if FiletoWrite == "" {
		fmt.Println("Need a file to write in -f")
	}
}

var KeyLocation string
var FiletoWrite string
var MinFileLength int

func init() {
	RootCmd.AddCommand(outCmd)
	outCmd.Flags().StringVarP(&KeyLocation, "key", "k", "", "key to pull data from")
	outCmd.Flags().StringVarP(&FiletoWrite, "file", "f", "", "where to write the data")
	outCmd.Flags().IntVarP(&MinFileLength, "length", "l", 10, "minimum amount of lines in the file")
}

--- 
+++ 
@@ -3,6 +3,7 @@
 import (
 	"fmt"
 	"github.com/spf13/cobra"
+	"os"
 )
 
 var outCmd = &cobra.Command{
@@ -19,9 +20,11 @@
 func checkFlags() {
 	if KeyLocation == "" {
 		fmt.Println("Need a key location in -k")
+		os.Exit(1)
 	}
 	if FiletoWrite == "" {
 		fmt.Println("Need a file to write in -f")
+		os.Exit(1)
 	}
 }
 
Exit the command if it doesn't have the right flags.
