Skip to content

Commit

Permalink
chore: experimenting with JSON/YAML as flag input
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderblue committed Jun 26, 2023
1 parent c100ce2 commit dfb94cc
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions internal/utils/command_do.go
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")
}

0 comments on commit dfb94cc

Please sign in to comment.