Skip to content

Commit fc64c80

Browse files
Katrina Owennywilken
authored andcommitted
Delete speculative implementation of prepare command (#677)
When I first started writing the new CLI I had some grand ideas about how submit should work, which required all sorts of complicated guessing, which in turn required a command to store settings on a per-track basis. We may still need to prepare things on a per-track basis, but the current implementation was highly speculative, and I decided that it would be better to delete it and start fresh when we know exactly what we need.
1 parent d2081f2 commit fc64c80

10 files changed

Lines changed: 2 additions & 588 deletions

File tree

cmd/prepare.go

Lines changed: 2 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,19 @@
11
package cmd
22

3-
import (
4-
"encoding/json"
5-
"errors"
6-
"fmt"
7-
"net/http"
8-
9-
"github.com/exercism/cli/api"
10-
"github.com/exercism/cli/config"
11-
"github.com/spf13/cobra"
12-
"github.com/spf13/pflag"
13-
"github.com/spf13/viper"
14-
)
3+
import "github.com/spf13/cobra"
154

165
// prepareCmd does necessary setup for Exercism and its tracks.
176
var prepareCmd = &cobra.Command{
187
Use: "prepare",
198
Aliases: []string{"p"},
209
Short: "Prepare does setup for Exercism and its tracks.",
2110
Long: `Prepare downloads settings and dependencies for Exercism and the language tracks.
22-
23-
When called with a track ID, it will do specific setup for that track. This
24-
might include downloading the files that the track maintainers have said are
25-
necessary for the track in general. Any files that are only necessary for a specific
26-
exercise will be downloaded along with the exercise.
27-
28-
To customize the CLI to suit your own preferences, use the configure command.
2911
`,
3012
RunE: func(cmd *cobra.Command, args []string) error {
31-
cfg := config.NewConfiguration()
32-
33-
v := viper.New()
34-
v.AddConfigPath(cfg.Dir)
35-
v.SetConfigName("user")
36-
v.SetConfigType("json")
37-
// Ignore error. If the file doesn't exist, that is fine.
38-
_ = v.ReadInConfig()
39-
cfg.UserViperConfig = v
40-
41-
return runPrepare(cfg, cmd.Flags(), args)
42-
},
43-
}
44-
45-
func runPrepare(cfg config.Configuration, flags *pflag.FlagSet, args []string) error {
46-
v := cfg.UserViperConfig
47-
48-
track, err := flags.GetString("track")
49-
if err != nil {
50-
return err
51-
}
52-
53-
if track == "" {
5413
return nil
55-
}
56-
client, err := api.NewClient(v.GetString("token"), v.GetString("apibaseurl"))
57-
if err != nil {
58-
return err
59-
}
60-
url := fmt.Sprintf("%s/tracks/%s", v.GetString("apibaseurl"), track)
61-
62-
req, err := client.NewRequest("GET", url, nil)
63-
if err != nil {
64-
return err
65-
}
66-
67-
res, err := client.Do(req)
68-
if err != nil {
69-
return err
70-
}
71-
defer res.Body.Close()
72-
73-
var payload prepareTrackPayload
74-
75-
if err := json.NewDecoder(res.Body).Decode(&payload); err != nil {
76-
return fmt.Errorf("unable to parse API response - %s", err)
77-
}
78-
79-
if res.StatusCode != http.StatusOK {
80-
return errors.New(payload.Error.Message)
81-
}
82-
83-
cliCfg, err := config.NewCLIConfig()
84-
if err != nil {
85-
return err
86-
}
87-
88-
t, ok := cliCfg.Tracks[track]
89-
if !ok {
90-
t = config.NewTrack(track)
91-
}
92-
if payload.Track.TestPattern != "" {
93-
t.IgnorePatterns = append(t.IgnorePatterns, payload.Track.TestPattern)
94-
}
95-
cliCfg.Tracks[track] = t
96-
97-
return cliCfg.Write()
98-
}
99-
100-
type prepareTrackPayload struct {
101-
Track struct {
102-
ID string `json:"id"`
103-
Language string `json:"language"`
104-
TestPattern string `json:"test_pattern"`
105-
} `json:"track"`
106-
Error struct {
107-
Type string `json:"type"`
108-
Message string `json:"message"`
109-
} `json:"error,omitempty"`
110-
}
111-
112-
func initPrepareCmd() {
113-
setupPrepareFlags(prepareCmd.Flags())
114-
}
115-
116-
func setupPrepareFlags(flags *pflag.FlagSet) {
117-
flags.StringP("track", "t", "", "the track you want to prepare")
14+
},
11815
}
11916

12017
func init() {
12118
RootCmd.AddCommand(prepareCmd)
122-
initPrepareCmd()
12319
}

cmd/prepare_test.go

Lines changed: 0 additions & 70 deletions
This file was deleted.

config/cli_config.go

Lines changed: 0 additions & 62 deletions
This file was deleted.

config/cli_config_test.go

Lines changed: 0 additions & 89 deletions
This file was deleted.

0 commit comments

Comments
 (0)