Skip to content

Commit effb5ac

Browse files
authored
Remove positional args for cli commands (#56)
remove positional args for cli commands
1 parent 0f4c68d commit effb5ac

File tree

3 files changed

+4
-19
lines changed

3 files changed

+4
-19
lines changed

Diff for: checks/command.go

+2-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package checks
22

33
import (
4-
"fmt"
54
"os/exec"
65
"strings"
76

@@ -10,15 +9,13 @@ import (
109

1110
func CLICommand(
1211
lesson api.Lesson,
13-
optionalPositionalArgs []string,
1412
) []api.CLICommandResult {
1513
data := lesson.Lesson.LessonDataCLICommand.CLICommandData
1614
responses := make([]api.CLICommandResult, len(data.Commands))
1715
for i, command := range data.Commands {
18-
finalCommand := interpolateArgs(command.Command, optionalPositionalArgs)
19-
responses[i].FinalCommand = finalCommand
16+
responses[i].FinalCommand = command.Command
2017

21-
cmd := exec.Command("sh", "-c", "LANG=en_US.UTF-8 "+finalCommand)
18+
cmd := exec.Command("sh", "-c", "LANG=en_US.UTF-8 "+command.Command)
2219
b, err := cmd.Output()
2320
if ee, ok := err.(*exec.ExitError); ok {
2421
responses[i].ExitCode = ee.ExitCode()
@@ -29,11 +26,3 @@ func CLICommand(
2926
}
3027
return responses
3128
}
32-
33-
func interpolateArgs(rawCommand string, optionalPositionalArgs []string) string {
34-
// replace $1, $2, etc. with the optional positional args
35-
for i, arg := range optionalPositionalArgs {
36-
rawCommand = strings.ReplaceAll(rawCommand, fmt.Sprintf("$%d", i+1), arg)
37-
}
38-
return rawCommand
39-
}

Diff for: cmd/submit.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ func submissionHandler(cmd *cobra.Command, args []string) error {
3030
cmd.SilenceUsage = true
3131
isSubmit := cmd.Name() == "submit" || forceSubmit
3232
lessonUUID := args[0]
33-
optionalPositionalArgs := []string{}
34-
if len(args) > 1 {
35-
optionalPositionalArgs = args[1:]
36-
}
3733

3834
lesson, err := api.FetchLesson(lessonUUID)
3935
if err != nil {
@@ -53,7 +49,7 @@ func submissionHandler(cmd *cobra.Command, args []string) error {
5349
render.HTTPRun(data, results)
5450
}
5551
case "type_cli_command":
56-
results := checks.CLICommand(*lesson, optionalPositionalArgs)
52+
results := checks.CLICommand(*lesson)
5753
data := *lesson.Lesson.LessonDataCLICommand
5854
if isSubmit {
5955
failure, err := api.SubmitCLICommandLesson(lessonUUID, results)

Diff for: version.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v1.9.0
1+
v1.9.1

0 commit comments

Comments
 (0)