/
workspace.go
46 lines (36 loc) · 1.08 KB
/
workspace.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package cmd
import (
"fmt"
"github.com/exercism/cli/config"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// workspaceCmd outputs the path to the person's workspace directory.
var workspaceCmd = &cobra.Command{
Use: "workspace",
Aliases: []string{"w"},
Short: "Print out the path to your Exercism workspace.",
Long: `Print out the path to your Exercism workspace.
This command can be used for scripting, or it can be combined with shell
commands to take you to your workspace.
For example you can run:
cd $(exercism workspace)
On Windows, this will work only with Powershell, however you would
need to be on the same drive as your workspace directory. Otherwise
nothing will happen.
`,
RunE: func(cmd *cobra.Command, args []string) error {
cfg := config.NewConfig()
v := viper.New()
v.AddConfigPath(cfg.Dir)
v.SetConfigName("user")
v.SetConfigType("json")
// Ignore error. If the file doesn't exist, that is fine.
_ = v.ReadInConfig()
fmt.Fprintf(Out, "%s\n", v.GetString("workspace"))
return nil
},
}
func init() {
RootCmd.AddCommand(workspaceCmd)
}