Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/301-flow-pull-request-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ 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
with:
version: 3.x

- name: Build
run: |
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/302-flow-publish-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ jobs:
checkout: 'true'
checkout-token: '${{ secrets.GITHUB_TOKEN }}'
setup-go: 'true'
go-version: '1.25'
go-version: '1.26.1'

- 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
Expand Down Expand Up @@ -84,10 +86,12 @@ jobs:
checkout: 'true'
checkout-token: '${{ secrets.GITHUB_TOKEN }}'
setup-go: 'true'
go-version: '1.25'
go-version: '1.26.1'

- 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 }}
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/copilot-setup-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ jobs:
- name: Setup Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version: 1.26.0

go-version: 1.26.1
3 changes: 1 addition & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '0.0.1'
version: '3'

tasks:
default:
Expand Down Expand Up @@ -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

69 changes: 69 additions & 0 deletions chewie/cmd/chewie/main.go
Original file line number Diff line number Diff line change
@@ -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))
}
81 changes: 81 additions & 0 deletions chewie/cmd/chewie/main_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
Loading