Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cli output handlers #3660

Merged
merged 14 commits into from
May 2, 2024
Merged

Add cli output handlers #3660

merged 14 commits into from
May 2, 2024

Conversation

xoxys
Copy link
Member

@xoxys xoxys commented Apr 28, 2024

❯ ./dist/woodpecker-cli pipeline ls --help
NAME:
   woodpecker-cli pipeline ls - show pipeline history

USAGE:
   woodpecker-cli pipeline ls [command options] <repo-id|repo-full-name>

OPTIONS:
   --output value  output format (default: "table")
   --no-header     don't print headers (default: false)
   --branch value  branch filter
   --event value   event filter
   --status value  status filter
   --limit value   limit the list size (default: 25)
   --help, -h      show help

########
# use default table output
❯ ./dist/woodpecker-cli pipeline ls --limit 2 2
NUMBER  STATUS   EVENT   BRANCH  COMMIT                                    AUTHOR
43      error    manual  main    473761d8b26b20f7c206408563d54cf998410329  woodpecker
42      success  push    main    473761d8b26b20f7c206408563d54cf998410329  woodpecker

########
# auto-fallback to table output
❯ ./dist/woodpecker-cli pipeline ls --limit 2 --output foo 2
NUMBER  STATUS   EVENT   BRANCH  COMMIT                                    AUTHOR
43      error    manual  main    473761d8b26b20f7c206408563d54cf998410329  woodpecker
42      success  push    main    473761d8b26b20f7c206408563d54cf998410329  woodpecker

########
# use explicit table output 
❯ ./dist/woodpecker-cli pipeline ls --limit 2 --output table 2
NUMBER  STATUS   EVENT   BRANCH  COMMIT                                    AUTHOR
43      error    manual  main    473761d8b26b20f7c206408563d54cf998410329  woodpecker
42      success  push    main    473761d8b26b20f7c206408563d54cf998410329  woodpecker

########
# customize table output 
❯ ./dist/woodpecker-cli pipeline ls --limit 2 --output table=number,status,event 2
NUMBER  STATUS   EVENT
43      error    manual
42      success  push

########
# customize table output and disable header
❯ ./dist/woodpecker-cli pipeline ls --limit 2 --output table=number,status,event --no-header 2
43  error    manual
42  success  push

########
# go crazy and use a template layout
❯ ./dist/woodpecker-cli pipeline ls --limit 2 --output go-template='{{range .}}{{printf "\x1b[33mPipeline #%d\x1b[0m\nStatus: %s\nEvent:%s\nCommit:%s\n\n" .Number .Status .Event .Commit}}{{end}}' 2
Pipeline #43
Status: error
Event:manual
Commit:473761d8b26b20f7c206408563d54cf998410329

Pipeline #42
Status: success
Event:push
Commit:473761d8b26b20f7c206408563d54cf998410329

@woodpecker-ci/maintainers I would like to get some feedback in this early state. Please let me know what you think about this implementation.

@xoxys xoxys marked this pull request as draft April 28, 2024 13:56
@xoxys xoxys changed the title return errors instead of panic Add cli output handlers Apr 28, 2024
@xoxys xoxys mentioned this pull request Apr 28, 2024
28 tasks
@xoxys xoxys added enhancement improve existing features cli labels Apr 28, 2024
@xoxys
Copy link
Member Author

xoxys commented Apr 28, 2024

I added mocks for the woodpecker-go client to add some cli tests. However, injecting mock clients into urfave/cli commands is a bit crappy, or I'm too stupid to find a better solution. If you have a better idea, please let me know, happy to change it.

@woodpecker-bot
Copy link
Collaborator

woodpecker-bot commented Apr 28, 2024

Deployment of preview was successful: https://woodpecker-ci-woodpecker-pr-3660.surge.sh

@xoxys xoxys marked this pull request as ready for review April 29, 2024 08:26
@xoxys xoxys requested a review from a team April 29, 2024 08:26
cli/common/flags.go Outdated Show resolved Hide resolved
cli/pipeline/create.go Show resolved Hide resolved
xoxys and others added 3 commits May 1, 2024 20:47
Co-authored-by: Anbraten <6918444+anbraten@users.noreply.github.com>
@xoxys xoxys enabled auto-merge (squash) May 2, 2024 06:40
@xoxys xoxys added this to the 2.5.0 milestone May 2, 2024
@xoxys xoxys merged commit e229a8e into main May 2, 2024
6 of 7 checks passed
@xoxys xoxys deleted the cli-output branch May 2, 2024 06:43
@woodpecker-bot woodpecker-bot mentioned this pull request May 2, 2024
1 task
6543 pushed a commit to 6543-forks/woodpecker that referenced this pull request Sep 5, 2024
Co-authored-by: Anbraten <6918444+anbraten@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli enhancement improve existing features highlight
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants