From 352704e4a88cb675cac85c8fa10ec8731aa4a6a8 Mon Sep 17 00:00:00 2001 From: Roger Barker Date: Thu, 2 Apr 2026 10:42:18 -0500 Subject: [PATCH 1/4] feat: Add initial go app Signed-off-by: Roger Barker --- Taskfile.yml | 2 +- chewie/cmd/chewie/main.go | 69 +++++++++++++++++++++++++++++ chewie/cmd/chewie/main_test.go | 81 ++++++++++++++++++++++++++++++++++ 3 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 chewie/cmd/chewie/main.go create mode 100644 chewie/cmd/chewie/main_test.go diff --git a/Taskfile.yml b/Taskfile.yml index 5cd69fe..9af9761 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,4 +1,4 @@ -version: '0.0.1' +version: '3' tasks: default: diff --git a/chewie/cmd/chewie/main.go b/chewie/cmd/chewie/main.go new file mode 100644 index 0000000..05dd590 --- /dev/null +++ b/chewie/cmd/chewie/main.go @@ -0,0 +1,69 @@ +package main + +import ( + "flag" + "fmt" + "io" + "os" +) + +const version = "0.0.1" + +const helpText = `chewie - Chewie CLI + +USAGE: + chewie [OPTIONS] + +OPTIONS + -h, --help Show this help message + -v, --version Show version information + +DESCRIPTION: + The chewie CLI tool interfaces with the Chewie GitHub App (github.com/swirldslabs/chewie). + It provides commands to manage and interact with Chewie's features, such as creating requests + and polling request status. The chewie CLI also allows for configuration of a repositories chewie + config for authorized users. The tool is intended to primarily be used in GitHub CI/CD environments. + +EXAMPLES: + chewie -h + chewie -v + +EXIT CODES: + 0 Command executed successfully + 2 Error Occurred +` + +var osExit = os.Exit + +func run(args []string, stdout, stderr io.Writer, stdin io.Reader) int { + fs := flag.NewFlagSet("chewie", flag.ContinueOnError) + fs.SetOutput(stderr) + + var ( + showHelp bool + showVer bool + ) + + fs.BoolVar(&showHelp, "h", false, "show help") + fs.BoolVar(&showHelp, "help", false, "show help") + fs.BoolVar(&showVer, "v", false, "show version") + fs.BoolVar(&showVer, "version", false, "show version") + + if err := fs.Parse(args); err != nil { + return 2 + } + + if showHelp || len(args) == 0 { + fmt.Fprint(stdout, helpText) + } + + if showVer { + fmt.Fprintf(stdout, "chewie CLI version %s\n", version) + } + + return 0 +} + +func main() { + osExit(run(os.Args[1:], os.Stdout, os.Stderr, os.Stdin)) +} diff --git a/chewie/cmd/chewie/main_test.go b/chewie/cmd/chewie/main_test.go new file mode 100644 index 0000000..001f670 --- /dev/null +++ b/chewie/cmd/chewie/main_test.go @@ -0,0 +1,81 @@ +package main + +import ( + "bytes" + "strings" + "testing" +) + +func TestRun_NoArgs(t *testing.T) { + var stdout, stderr bytes.Buffer + code := run([]string{}, &stdout, &stderr, nil) + if code != 0 { + t.Errorf("expected exit code 0, got %d", code) + } + if !strings.Contains(stdout.String(), "chewie - Chewie CLI") { + t.Errorf("expected help text in stdout, got: %q", stdout.String()) + } +} + +func TestRun_ShortHelp(t *testing.T) { + var stdout, stderr bytes.Buffer + code := run([]string{"-h"}, &stdout, &stderr, nil) + if code != 0 { + t.Errorf("expected exit code 0, got %d", code) + } + if !strings.Contains(stdout.String(), "chewie - Chewie CLI") { + t.Errorf("expected help text in stdout, got: %q", stdout.String()) + } +} + +func TestRun_LongHelp(t *testing.T) { + var stdout, stderr bytes.Buffer + code := run([]string{"--help"}, &stdout, &stderr, nil) + if code != 0 { + t.Errorf("expected exit code 0, got %d", code) + } + if !strings.Contains(stdout.String(), "chewie - Chewie CLI") { + t.Errorf("expected help text in stdout, got: %q", stdout.String()) + } +} + +func TestRun_ShortVersion(t *testing.T) { + var stdout, stderr bytes.Buffer + code := run([]string{"-v"}, &stdout, &stderr, nil) + if code != 0 { + t.Errorf("expected exit code 0, got %d", code) + } + if !strings.Contains(stdout.String(), version) { + t.Errorf("expected version %q in stdout, got: %q", version, stdout.String()) + } +} + +func TestRun_LongVersion(t *testing.T) { + var stdout, stderr bytes.Buffer + code := run([]string{"--version"}, &stdout, &stderr, nil) + if code != 0 { + t.Errorf("expected exit code 0, got %d", code) + } + if !strings.Contains(stdout.String(), version) { + t.Errorf("expected version %q in stdout, got: %q", version, stdout.String()) + } +} + +func TestRun_InvalidFlag(t *testing.T) { + var stdout, stderr bytes.Buffer + code := run([]string{"--unknown"}, &stdout, &stderr, nil) + if code != 2 { + t.Errorf("expected exit code 2, got %d", code) + } +} + +func TestRun_HelpContainsUsage(t *testing.T) { + var stdout, stderr bytes.Buffer + run([]string{"-h"}, &stdout, &stderr, nil) + out := stdout.String() + for _, expected := range []string{"USAGE:", "OPTIONS", "DESCRIPTION:", "EXAMPLES:", "EXIT CODES:"} { + if !strings.Contains(out, expected) { + t.Errorf("help text missing section %q", expected) + } + } +} From 7d8edd53bf5e23fc6bc98e734837ba3d9e9e3ad5 Mon Sep 17 00:00:00 2001 From: Roger Barker Date: Thu, 2 Apr 2026 10:54:40 -0500 Subject: [PATCH 2/4] chore: Update to install task Signed-off-by: Roger Barker --- .github/workflows/301-flow-pull-request-checks.yaml | 5 +++++ .github/workflows/302-flow-publish-release.yaml | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/301-flow-pull-request-checks.yaml b/.github/workflows/301-flow-pull-request-checks.yaml index 0a649b1..c2c0177 100644 --- a/.github/workflows/301-flow-pull-request-checks.yaml +++ b/.github/workflows/301-flow-pull-request-checks.yaml @@ -27,6 +27,11 @@ jobs: setup-go: 'true' go-version: '1.26.0' + - name: Install Task + uses: go-task/setup-task@3be4020d41929789a01026e0e427a4321ce0ad44 # v2.0.0 + with: + version: 3.x + - name: Build run: | task build diff --git a/.github/workflows/302-flow-publish-release.yaml b/.github/workflows/302-flow-publish-release.yaml index 7613dc7..9cfac29 100644 --- a/.github/workflows/302-flow-publish-release.yaml +++ b/.github/workflows/302-flow-publish-release.yaml @@ -24,7 +24,9 @@ jobs: go-version: '1.25' - name: Install Task - run: go install github.com/go-task/task/v3/cmd/task@latest + uses: go-task/setup-task@3be4020d41929789a01026e0e427a4321ce0ad44 # v2.0.0 + with: + version: 3.x - name: Run tests run: task test @@ -87,7 +89,9 @@ jobs: go-version: '1.25' - name: Install Task - run: go install github.com/go-task/task/v3/cmd/task@latest + uses: go-task/setup-task@3be4020d41929789a01026e0e427a4321ce0ad44 # v2.0.0 + with: + version: 3.x - name: Build release binaries run: task build-release VERSION=${{ needs.release.outputs.new_release_version }} From 4cd711d53349c66ff4540cb30ce8c1582f10b4fb Mon Sep 17 00:00:00 2001 From: Roger Barker Date: Thu, 2 Apr 2026 10:57:15 -0500 Subject: [PATCH 3/4] chore: Update go-version Signed-off-by: Roger Barker --- .github/workflows/301-flow-pull-request-checks.yaml | 2 +- .github/workflows/302-flow-publish-release.yaml | 4 ++-- .github/workflows/copilot-setup-steps.yml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/301-flow-pull-request-checks.yaml b/.github/workflows/301-flow-pull-request-checks.yaml index c2c0177..111bad5 100644 --- a/.github/workflows/301-flow-pull-request-checks.yaml +++ b/.github/workflows/301-flow-pull-request-checks.yaml @@ -25,7 +25,7 @@ jobs: checkout-ref: '${{ github.ref }}' checkout-token: '${{ secrets.GITHUB_TOKEN }}' setup-go: 'true' - go-version: '1.26.0' + go-version: '1.26.1' - name: Install Task uses: go-task/setup-task@3be4020d41929789a01026e0e427a4321ce0ad44 # v2.0.0 diff --git a/.github/workflows/302-flow-publish-release.yaml b/.github/workflows/302-flow-publish-release.yaml index 9cfac29..c18e1b7 100644 --- a/.github/workflows/302-flow-publish-release.yaml +++ b/.github/workflows/302-flow-publish-release.yaml @@ -21,7 +21,7 @@ jobs: checkout: 'true' checkout-token: '${{ secrets.GITHUB_TOKEN }}' setup-go: 'true' - go-version: '1.25' + go-version: '1.26.1' - name: Install Task uses: go-task/setup-task@3be4020d41929789a01026e0e427a4321ce0ad44 # v2.0.0 @@ -86,7 +86,7 @@ jobs: checkout: 'true' checkout-token: '${{ secrets.GITHUB_TOKEN }}' setup-go: 'true' - go-version: '1.25' + go-version: '1.26.1' - name: Install Task uses: go-task/setup-task@3be4020d41929789a01026e0e427a4321ce0ad44 # v2.0.0 diff --git a/.github/workflows/copilot-setup-steps.yml b/.github/workflows/copilot-setup-steps.yml index cc7648f..5f236ef 100644 --- a/.github/workflows/copilot-setup-steps.yml +++ b/.github/workflows/copilot-setup-steps.yml @@ -30,5 +30,5 @@ jobs: - name: Setup Go uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 with: - go-version: 1.26.0 + go-version: 1.26.1 From 1aca1a38ef23dd5b4e65c4578863705341333c4e Mon Sep 17 00:00:00 2001 From: Roger Barker Date: Thu, 2 Apr 2026 10:57:42 -0500 Subject: [PATCH 4/4] chore: Tidy new lines Signed-off-by: Roger Barker --- .github/workflows/copilot-setup-steps.yml | 1 - Taskfile.yml | 1 - 2 files changed, 2 deletions(-) diff --git a/.github/workflows/copilot-setup-steps.yml b/.github/workflows/copilot-setup-steps.yml index 5f236ef..cf2fd0c 100644 --- a/.github/workflows/copilot-setup-steps.yml +++ b/.github/workflows/copilot-setup-steps.yml @@ -31,4 +31,3 @@ jobs: uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 with: go-version: 1.26.1 - diff --git a/Taskfile.yml b/Taskfile.yml index 9af9761..b08ac4f 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -88,4 +88,3 @@ tasks: - GOOS=linux GOARCH=arm64 go build -o ../dist/chewie-linux-arm64 ./cmd/chewie - GOOS=darwin GOARCH=amd64 go build -o ../dist/chewie-darwin-amd64 ./cmd/chewie - GOOS=darwin GOARCH=arm64 go build -o ../dist/chewie-darwin-arm64 ./cmd/chewie -