-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: experimenting with JSON/YAML as flag input
- Loading branch information
1 parent
c100ce2
commit dfb94cc
Showing
1 changed file
with
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
stringFlag string | ||
intFlag int | ||
flags string // the json file path | ||
) | ||
|
||
var cmdDo = &cobra.Command{ | ||
Use: "do", | ||
Short: "Provide json file as cmd args", | ||
Long: `Testing json file as arguments to a command`, | ||
Example: `newrelic do --file=./path/to/file`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("testing") | ||
|
||
fileType := filepath.Ext(flags) | ||
|
||
// if jsonFile { | ||
// handle json | ||
// } | ||
|
||
// if yamlFile { | ||
// handle yaml | ||
// } | ||
|
||
fmt.Println("Content Type of file is: " + fileType) | ||
}, | ||
} | ||
|
||
func init() { | ||
Command.AddCommand(cmdDo) | ||
|
||
cmdDo.Flags().StringVarP(&flags, "flags", "f", "", "a file that contains the flags for the command") | ||
|
||
cmdDo.Flags().StringVar(&stringFlag, "stringFlag", "", "A flag with a string value") | ||
cmdDo.Flags().IntVar(&intFlag, "intFlag", 0, "A flag with an integer value") | ||
} |