Skip to content

Commit cf59ff6

Browse files
authored
Merge pull request #20 from ThreeDotsLabs/pick
Add jump command
2 parents d5180c0 + a0b3862 commit cf59ff6

File tree

8 files changed

+858
-75
lines changed

8 files changed

+858
-75
lines changed

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ require (
66
github.com/BurntSushi/toml v0.4.1
77
github.com/fatih/color v1.12.0
88
github.com/golang/protobuf v1.5.3
9+
github.com/google/uuid v1.3.1
910
github.com/hexops/gotextdiff v1.0.3
11+
github.com/manifoldco/promptui v0.9.0
1012
github.com/pkg/errors v0.9.1
1113
github.com/sirupsen/logrus v1.8.1
1214
github.com/spf13/afero v1.6.0
@@ -18,6 +20,7 @@ require (
1820
)
1921

2022
require (
23+
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
2124
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
2225
github.com/davecgh/go-spew v1.1.1 // indirect
2326
github.com/google/go-cmp v0.6.0 // indirect

go.sum

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
22
github.com/BurntSushi/toml v0.4.1 h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw=
33
github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
4+
github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE=
5+
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
6+
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8=
7+
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
8+
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8=
9+
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
410
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
511
github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM=
612
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
@@ -16,6 +22,8 @@ github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu
1622
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
1723
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
1824
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
25+
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
26+
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
1927
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
2028
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
2129
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
@@ -27,6 +35,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
2735
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
2836
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
2937
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
38+
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
39+
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg=
3040
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
3141
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
3242
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
@@ -63,6 +73,7 @@ golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1m
6373
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
6474
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
6575
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
76+
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
6677
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
6778
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
6879
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

tdl/main.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,47 @@ var app = &cli.App{
203203
return newHandlers(c).Clone(c.Context, executionID)
204204
},
205205
},
206+
{
207+
Name: "jump",
208+
Usage: "Jump to the exercise to work on. Provide the ID or keep empty for interactive mode",
209+
UsageText: `Provide one of:
210+
- exercise ID (e.g., 48cfc4c8-ceab-4438-8082-9ec6e322df58)
211+
- exercise name with module (e.g., 04-module/05-exercise)
212+
- exercise name, assuming current module (e.g., 05-exercise)
213+
- just the numbers (e.g., 4/5, or 5)
214+
- latest - to go back to the last exercise
215+
216+
Leave empty to pick interactively.
217+
218+
Note: after completing this exercise, the next exercise will be the last one you didn't complete yet'.`,
219+
220+
ArgsUsage: fmt.Sprintf(
221+
"[exerciseID or name]",
222+
),
223+
Action: func(c *cli.Context) error {
224+
handlers := newHandlers(c)
225+
var err error
226+
227+
exerciseID := c.Args().First()
228+
if exerciseID == "" {
229+
exerciseID, err = handlers.SelectExercise(c.Context)
230+
if err != nil {
231+
return err
232+
}
233+
} else {
234+
exerciseID, err = handlers.FindExercise(c.Context, exerciseID)
235+
if err != nil {
236+
return err
237+
}
238+
}
239+
240+
if exerciseID == "" {
241+
return nil
242+
}
243+
244+
return handlers.Jump(c.Context, exerciseID)
245+
},
246+
},
206247
},
207248
},
208249
{

trainings/api/protobuf/server.proto

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ service Trainings {
1414
rpc VerifyExercise(VerifyExerciseRequest) returns (stream VerifyExerciseResponse) {};
1515

1616
rpc GetSolutionFiles(GetSolutionFilesRequest) returns (GetSolutionFilesResponse) {};
17+
18+
rpc GetExercises(GetExercisesRequest) returns (GetExercisesResponse) {};
19+
rpc GetExercise(GetExerciseRequest) returns (NextExerciseResponse) {};
1720
}
1821

1922
message InitRequest {
@@ -103,4 +106,31 @@ message GetSolutionFilesResponse {
103106
string dir = 2;
104107
string exercise_id = 3;
105108
repeated File files_to_create = 4;
106-
}
109+
}
110+
111+
message GetExercisesRequest {
112+
string training_name = 1;
113+
string token = 2;
114+
}
115+
116+
message GetExercisesResponse {
117+
message Module {
118+
string id = 1;
119+
string name = 2;
120+
repeated Exercise exercises = 3;
121+
}
122+
123+
message Exercise {
124+
string id = 1;
125+
string name = 2;
126+
}
127+
128+
repeated Module modules = 1;
129+
}
130+
131+
message GetExerciseRequest {
132+
string training_name = 1;
133+
string token = 2;
134+
string exercise_id = 3;
135+
}
136+

0 commit comments

Comments
 (0)