From 40ba95770bf5d29ef6ce364738f2f4cd30b7d95f Mon Sep 17 00:00:00 2001 From: Paul Kuruvilla Date: Tue, 27 Aug 2024 19:18:13 +0100 Subject: [PATCH 1/2] update uncomment usage --- starter_templates/go/code/cmd/mygrep/main.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/starter_templates/go/code/cmd/mygrep/main.go b/starter_templates/go/code/cmd/mygrep/main.go index 982c43d..7760845 100644 --- a/starter_templates/go/code/cmd/mygrep/main.go +++ b/starter_templates/go/code/cmd/mygrep/main.go @@ -1,14 +1,16 @@ package main import ( - // Uncomment this to pass the first stage - // "bytes" + "bytes" "fmt" "io" "os" "unicode/utf8" ) +// Ensures gofmt doesn't remove the "bytes" import above (feel free to remove this!) +var _ = bytes.ContainsAny + // Usage: echo | your_grep.sh -E func main() { if len(os.Args) < 3 || os.Args[1] != "-E" { From 336ae921b9d61498ae50bd92a607a3eafff9224f Mon Sep 17 00:00:00 2001 From: Paul Kuruvilla Date: Tue, 27 Aug 2024 19:19:49 +0100 Subject: [PATCH 2/2] update uncomment usage --- compiled_starters/go/cmd/mygrep/main.go | 6 +++-- solutions/go/01-oq4/code/cmd/mygrep/main.go | 3 +++ .../go/01-oq4/diff/cmd/mygrep/main.go.diff | 24 +------------------ solutions/go/01-oq4/explanation.md | 5 ---- 4 files changed, 8 insertions(+), 30 deletions(-) diff --git a/compiled_starters/go/cmd/mygrep/main.go b/compiled_starters/go/cmd/mygrep/main.go index 982c43d..7760845 100644 --- a/compiled_starters/go/cmd/mygrep/main.go +++ b/compiled_starters/go/cmd/mygrep/main.go @@ -1,14 +1,16 @@ package main import ( - // Uncomment this to pass the first stage - // "bytes" + "bytes" "fmt" "io" "os" "unicode/utf8" ) +// Ensures gofmt doesn't remove the "bytes" import above (feel free to remove this!) +var _ = bytes.ContainsAny + // Usage: echo | your_grep.sh -E func main() { if len(os.Args) < 3 || os.Args[1] != "-E" { diff --git a/solutions/go/01-oq4/code/cmd/mygrep/main.go b/solutions/go/01-oq4/code/cmd/mygrep/main.go index 0724a6e..4a059d2 100644 --- a/solutions/go/01-oq4/code/cmd/mygrep/main.go +++ b/solutions/go/01-oq4/code/cmd/mygrep/main.go @@ -8,6 +8,9 @@ import ( "unicode/utf8" ) +// Ensures gofmt doesn't remove the "bytes" import above (feel free to remove this!) +var _ = bytes.ContainsAny + // Usage: echo | your_grep.sh -E func main() { if len(os.Args) < 3 || os.Args[1] != "-E" { diff --git a/solutions/go/01-oq4/diff/cmd/mygrep/main.go.diff b/solutions/go/01-oq4/diff/cmd/mygrep/main.go.diff index e03f6cd..6739228 100644 --- a/solutions/go/01-oq4/diff/cmd/mygrep/main.go.diff +++ b/solutions/go/01-oq4/diff/cmd/mygrep/main.go.diff @@ -1,26 +1,4 @@ -@@ -1,54 +1,49 @@ - package main - - import ( -- // Uncomment this to pass the first stage -- // "bytes" -+ "bytes" - "fmt" - "io" - "os" - "unicode/utf8" - ) - - // Usage: echo | your_grep.sh -E - func main() { - if len(os.Args) < 3 || os.Args[1] != "-E" { - fmt.Fprintf(os.Stderr, "usage: mygrep -E \n") - os.Exit(2) // 1 means no lines were selected, >1 means error - } - - pattern := os.Args[2] - - line, err := io.ReadAll(os.Stdin) // assume we're only dealing with a single line +@@ -24,33 +24,29 @@ if err != nil { fmt.Fprintf(os.Stderr, "error: read input text: %v\n", err) os.Exit(2) diff --git a/solutions/go/01-oq4/explanation.md b/solutions/go/01-oq4/explanation.md index 8adf16f..89f94c1 100644 --- a/solutions/go/01-oq4/explanation.md +++ b/solutions/go/01-oq4/explanation.md @@ -2,11 +2,6 @@ The entry point for your writers-stg implementation is in `cmd/mygrep/main.go`. Study and uncomment the relevant code: -```go -// Uncomment this to pass the first stage -"bytes" -``` - ```go // Uncomment this to pass the first stage ok = bytes.ContainsAny(line, pattern)