Skip to content

Commit

Permalink
add set command for configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
fantasticrabbit committed Nov 12, 2021
1 parent cc8e9ee commit e146c46
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cmd/gettask.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ var taskCmd = &cobra.Command{
return nil
},
Run: func(cmd *cobra.Command, args []string) {
viper.BindPFlag("custom", cmd.Flags().Lookup("custom"))
viper.BindPFlag("subtasks", cmd.Flags().Lookup("subtasks"))

var t = internal.TaskRequest{
TaskID: strings.Trim(args[0], "#"),
CustomTask: viper.GetBool("custom"),
Expand All @@ -34,7 +37,5 @@ var taskCmd = &cobra.Command{
func init() {
getCmd.AddCommand(taskCmd)
taskCmd.Flags().BoolP("custom", "c", false, "task id provided is a clickup custom task id")
viper.BindPFlag("custom", taskCmd.Flags().Lookup("custom"))
taskCmd.Flags().BoolP("subtasks", "s", false, "include subtasks in output")
viper.BindPFlag("subtasks", taskCmd.Flags().Lookup("subtasks"))
}
40 changes: 40 additions & 0 deletions cmd/set.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package cmd

import (
"errors"

"github.com/spf13/cobra"
"github.com/spf13/viper"
)

// setCmd represents the set command
var setCmd = &cobra.Command{
Use: "set",
Short: "sets config options",
Long: `set is used to configure extended options and save
them to the config file`,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
return errors.New("incorrect number of arguments")
}
return nil
},
Run: func(cmd *cobra.Command, args []string) {
keys := []string{"team", "port"}
for _, key := range keys {
x, _ := cmd.Flags().GetString(key)
if x != "" {
viper.BindPFlag(key, cmd.Flags().Lookup(key))
viper.WriteConfigAs(config_file)
println("Saved", key, "in config file")
}
}

},
}

func init() {
rootCmd.AddCommand(setCmd)
setCmd.Flags().StringP("team", "", "", "set the Team ID")
setCmd.Flags().StringP("port", "", "", "set the Redirect URL Port number")
}

0 comments on commit e146c46

Please sign in to comment.