Skip to content

Commit d1d5eba

Browse files
committed
Merge branch 'master' into test-results
2 parents 3b68d97 + a99b672 commit d1d5eba

File tree

15 files changed

+687
-229
lines changed

15 files changed

+687
-229
lines changed

tdl/main.go

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,31 @@ func main() {
3131
}
3232
}
3333

34+
var configureFlags = []cli.Flag{
35+
&cli.StringFlag{
36+
Name: "server",
37+
Usage: "custom server",
38+
Hidden: true,
39+
},
40+
&cli.BoolFlag{
41+
Name: "insecure",
42+
Usage: "do not verify certificate",
43+
Hidden: true,
44+
},
45+
&cli.StringFlag{
46+
Name: "region",
47+
Usage: "the region to use (eu or us)",
48+
},
49+
&cli.BoolFlag{
50+
Name: "override",
51+
Usage: "if config already exists, it will be overridden",
52+
// deprecated, backward compatibility
53+
Hidden: true,
54+
},
55+
}
56+
57+
var tokenDocs = fmt.Sprintf("token from %s", internal.WebsiteAddress)
58+
3459
var app = &cli.App{
3560
Name: "tdl",
3661
Usage: "https://threedots.tech/ CLI.",
@@ -84,30 +109,9 @@ var app = &cli.App{
84109
Subcommands: []*cli.Command{
85110
{
86111
Name: "configure",
87-
Usage: "connect your environment with platform account",
88-
ArgsUsage: fmt.Sprintf("<token from %s>", internal.WebsiteAddress),
89-
Flags: []cli.Flag{
90-
&cli.StringFlag{
91-
Name: "server",
92-
Usage: "custom server",
93-
Hidden: true,
94-
},
95-
&cli.BoolFlag{
96-
Name: "insecure",
97-
Usage: "do not verify certificate",
98-
Hidden: true,
99-
},
100-
&cli.StringFlag{
101-
Name: "region",
102-
Usage: "the region to use (eu or us)",
103-
},
104-
&cli.BoolFlag{
105-
Name: "override",
106-
Usage: "if config already exists, it will be overridden",
107-
// deprecated, backward compatibility
108-
Hidden: true,
109-
},
110-
},
112+
Usage: "connect your environment with https://academy.threedots.tech/ account",
113+
ArgsUsage: fmt.Sprintf("<%s>", tokenDocs),
114+
Flags: configureFlags,
111115
Action: func(c *cli.Context) error {
112116
token := c.Args().First()
113117

@@ -130,6 +134,10 @@ var app = &cli.App{
130134
"<trainingID from %s> [directory, if empty defaults to trainingID]",
131135
internal.WebsiteAddress,
132136
),
137+
Flags: append(configureFlags, &cli.StringFlag{
138+
Name: "token",
139+
Usage: tokenDocs,
140+
}),
133141
Usage: "initialise training files in your current directory",
134142
Action: func(c *cli.Context) error {
135143
trainingID := c.Args().First()
@@ -143,7 +151,22 @@ var app = &cli.App{
143151
dir = trainingID
144152
}
145153

146-
return newHandlers(c).Init(c.Context, trainingID, dir)
154+
handlers := newHandlers(c)
155+
156+
if c.String("token") != "" {
157+
err := handlers.ConfigureGlobally(
158+
c.Context,
159+
c.String("token"),
160+
c.String("server"),
161+
c.String("region"),
162+
c.Bool("insecure"),
163+
)
164+
if err != nil {
165+
return fmt.Errorf("could not configure training: %w", err)
166+
}
167+
}
168+
169+
return handlers.Init(c.Context, trainingID, dir)
147170
},
148171
},
149172
{
@@ -247,6 +270,14 @@ Note: after completing this exercise, the next exercise will be the last one you
247270
return handlers.Jump(c.Context, exerciseID)
248271
},
249272
},
273+
{
274+
Name: "skip",
275+
Usage: "Skip the current exercise and the rest of the module (only selected modules)",
276+
ArgsUsage: "",
277+
Action: func(c *cli.Context) error {
278+
return newHandlers(c).Skip(c.Context)
279+
},
280+
},
250281
},
251282
},
252283
{

trainings/api/protobuf/server.proto

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ service Trainings {
1717

1818
rpc GetExercises(GetExercisesRequest) returns (GetExercisesResponse) {};
1919
rpc GetExercise(GetExerciseRequest) returns (NextExerciseResponse) {};
20+
21+
rpc SkipExercise(SkipExerciseRequest) returns (SkipExerciseResponse) {};
2022
}
2123

2224
message InitRequest {
@@ -63,6 +65,20 @@ message NextExerciseResponse {
6365
repeated File files_to_create = 3;
6466

6567
bool is_text_only = 5;
68+
bool is_optional = 6;
69+
70+
message Module {
71+
string id = 1;
72+
string name = 2;
73+
}
74+
75+
message Exercise {
76+
string id = 1;
77+
Module module = 2;
78+
string name = 3;
79+
}
80+
81+
Exercise exercise = 7;
6682
}
6783

6884
message NextExercise {
@@ -136,6 +152,7 @@ message GetExercisesResponse {
136152
message Exercise {
137153
string id = 1;
138154
string name = 2;
155+
bool is_skipped = 3;
139156
}
140157

141158
repeated Module modules = 1;
@@ -146,3 +163,11 @@ message GetExerciseRequest {
146163
string token = 2;
147164
string exercise_id = 3;
148165
}
166+
167+
message SkipExerciseRequest {
168+
string training_name = 1;
169+
string exercise_id = 2;
170+
string token = 3;
171+
}
172+
173+
message SkipExerciseResponse {}

trainings/clone.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
func (h *Handlers) Clone(ctx context.Context, executionID string, directory string) error {
17-
resp, err := h.newGrpcClient(ctx).GetSolutionFiles(ctx, &genproto.GetSolutionFilesRequest{
17+
resp, err := h.newGrpcClient().GetSolutionFiles(ctx, &genproto.GetSolutionFilesRequest{
1818
ExecutionId: executionID,
1919
})
2020
if err != nil {

trainings/config/exercise.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type ExerciseConfig struct {
1313
ExerciseID string `toml:"exercise_id"`
1414
Directory string `toml:"directory"`
1515
IsTextOnly bool `toml:"is_text_only"`
16+
IsOptional bool `toml:"is_optional"`
1617
}
1718

1819
func (c Config) WriteExerciseConfig(trainingRootFs afero.Fs, cfg ExerciseConfig) error {

trainings/configure.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func (h *Handlers) ConfigureGlobally(ctx context.Context, token, serverAddr, reg
1515
}
1616
}
1717

18-
resp, err := h.newGrpcClientWithAddr(ctx, serverAddr, region, insecure).Init(
18+
resp, err := h.newGrpcClientWithAddr(serverAddr, region, insecure).Init(
1919
ctxWithRequestHeader(ctx, h.cliMetadata),
2020
&genproto.InitRequest{
2121
Token: token,

0 commit comments

Comments
 (0)