Skip to content

Commit

Permalink
Merge pull request sequelize#449 from exercism/nextercism-configure-show
Browse files Browse the repository at this point in the history
[nextercism] Implement show flag for configure command
  • Loading branch information
Katrina Owen authored Aug 17, 2017
2 parents ff66efa + ee62737 commit b8464ac
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions cmd/configure.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package cmd

import (
"fmt"
"os"
"text/tabwriter"

"github.com/exercism/cli/config"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand All @@ -26,29 +30,41 @@ You can also override certain default settings to suit your preferences.
`,
Run: func(cmd *cobra.Command, args []string) {
usrCfg := config.NewEmptyUserConfig()

err := usrCfg.Load(viperUserConfig)
BailOnError(err)

err = usrCfg.Write()
apiCfg := config.NewEmptyAPIConfig()
err = apiCfg.Load(viperAPIConfig)
BailOnError(err)

apiCfg := config.NewEmptyAPIConfig()
show, err := cmd.Flags().GetBool("show")
BailOnError(err)

err = apiCfg.Load(viperAPIConfig)
if show {
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
defer w.Flush()

fmt.Fprintln(w, "")
fmt.Fprintln(w, fmt.Sprintf("Config dir:\t%s", config.Dir()))
fmt.Fprintln(w, fmt.Sprintf("-t, --token\t%s", usrCfg.Token))
fmt.Fprintln(w, fmt.Sprintf("-w, --workspace\t%s", usrCfg.Workspace))
fmt.Fprintln(w, fmt.Sprintf("-a, --api\t%s", apiCfg.BaseURL))
return
}

err = usrCfg.Write()
BailOnError(err)

err = apiCfg.Write()
BailOnError(err)

return
},
}

func initConfigureCmd() {
configureCmd.Flags().StringP("token", "t", "", "authentication token used to connect to exercism.io")
configureCmd.Flags().StringP("workspace", "w", "", "directory for exercism exercises")
configureCmd.Flags().StringP("api", "a", "", "API base url")
configureCmd.Flags().BoolP("show", "s", false, "show the current configuration")

viperUserConfig = viper.New()
viperUserConfig.BindPFlag("token", configureCmd.Flags().Lookup("token"))
Expand Down

0 comments on commit b8464ac

Please sign in to comment.