Skip to content

Commit 03413f5

Browse files
committed
.
0 parents  commit 03413f5

52 files changed

Lines changed: 1870 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: build
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
uses: charmbracelet/meta/.github/workflows/build.yml@main
8+
9+
lint:
10+
uses: charmbracelet/meta/.github/workflows/lint.yml@main
11+
12+
snapshot:
13+
uses: charmbracelet/meta/.github/workflows/snapshot.yml@main
14+
secrets:
15+
goreleaser_key: ${{ secrets.GORELEASER_KEY }}

.github/workflows/goreleaser.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
2+
3+
name: goreleaser
4+
5+
on:
6+
push:
7+
tags:
8+
- v*.*.*
9+
10+
concurrency:
11+
group: goreleaser
12+
cancel-in-progress: true
13+
14+
jobs:
15+
goreleaser:
16+
uses: charmbracelet/meta/.github/workflows/goreleaser.yml@main
17+
secrets:
18+
docker_username: ${{ secrets.DOCKERHUB_USERNAME }}
19+
docker_token: ${{ secrets.DOCKERHUB_TOKEN }}
20+
gh_pat: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
21+
goreleaser_key: ${{ secrets.GORELEASER_KEY }}
22+
aur_key: ${{ secrets.AUR_KEY }}
23+
fury_token: ${{ secrets.FURY_TOKEN }}
24+
nfpm_gpg_key: ${{ secrets.NFPM_GPG_KEY }}
25+
nfpm_passphrase: ${{ secrets.NFPM_PASSPHRASE }}
26+
macos_sign_p12: ${{ secrets.MACOS_SIGN_P12 }}
27+
macos_sign_password: ${{ secrets.MACOS_SIGN_PASSWORD }}
28+
macos_notary_issuer_id: ${{ secrets.MACOS_NOTARY_ISSUER_ID }}
29+
macos_notary_key_id: ${{ secrets.MACOS_NOTARY_KEY_ID }}
30+
macos_notary_key: ${{ secrets.MACOS_NOTARY_KEY }}

.github/workflows/lint-sync.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: lint-sync
2+
on:
3+
schedule:
4+
- cron: "0 0 * * 0"
5+
workflow_dispatch:
6+
7+
permissions:
8+
contents: write
9+
pull-requests: write
10+
11+
jobs:
12+
lint:
13+
uses: charmbracelet/meta/.github/workflows/lint-sync.yml@main

.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# core
2+
.DS_Store
3+
.env
4+
.env*.local
5+
.env.production
6+
output
7+
dist
8+
target
9+
.idea
10+
.cache
11+
.output
12+
node_modules
13+
package-lock.json
14+
yarn.lock
15+
.vercel
16+
*.db
17+
.repo_ignore
18+
i.*
19+
i-*
20+
i/
21+
internal/
22+
past.*
23+
past-*
24+
past/
25+
*.log
26+
private
27+
.blade
28+
29+
dist/
30+
example/bin

.golangci.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
version: "2"
2+
run:
3+
tests: false
4+
linters:
5+
enable:
6+
- bodyclose
7+
- exhaustive
8+
- goconst
9+
- godot
10+
- gomoddirectives
11+
- goprintffuncname
12+
- gosec
13+
- misspell
14+
- nakedret
15+
- nestif
16+
- nilerr
17+
- noctx
18+
- nolintlint
19+
- prealloc
20+
- revive
21+
- rowserrcheck
22+
- sqlclosecheck
23+
- tparallel
24+
- unconvert
25+
- unparam
26+
- whitespace
27+
- wrapcheck
28+
exclusions:
29+
generated: lax
30+
presets:
31+
- common-false-positives
32+
issues:
33+
max-issues-per-linter: 0
34+
max-same-issues: 0
35+
formatters:
36+
enable:
37+
- gofumpt
38+
- goimports
39+
exclusions:
40+
generated: lax

.goreleaser.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# yaml-language-server: $schema=https://goreleaser.com/static/schema-pro.json
2+
version: 2
3+
includes:
4+
- from_url:
5+
url: charmbracelet/meta/main/goreleaser-lib.yaml

Taskfile.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: 3
2+
tasks:
3+
screenshots:
4+
cmds:
5+
- freeze -W 700 -H 800 --config full --output ./example/1.svg --execute "./example/run -h"
6+
- freeze -W 700 -H 400 --config full --output ./example/2.svg --execute "./example/run -e"
7+
- freeze -W 700 -H 400 --config full --output ./example/3.svg --execute "./example/run --this-flag-doesnt-exist"

example/main.go

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// Package main is a fang example.
2+
package main
3+
4+
import (
5+
"context"
6+
"errors"
7+
"os"
8+
"time"
9+
10+
"github.com/charmbracelet/fang"
11+
"github.com/spf13/cobra"
12+
)
13+
14+
func main() {
15+
var foo string
16+
var bar int
17+
var baz float64
18+
var d time.Duration
19+
var eerr bool
20+
21+
cmd := &cobra.Command{
22+
Use: "example [args]",
23+
Short: "An example program!",
24+
Long: `A little example program!
25+
26+
It doesn’t really do anything, but that’s the point.™`,
27+
Example: `
28+
# Run it:
29+
example
30+
31+
# Run it with some arguments:
32+
FOO=bar ZAZ="quoted value" example --name=Carlos -a -s Becker -a
33+
34+
# Run a subcommand with an argument:
35+
example sub --async --foo=xyz --async arguments
36+
37+
# Run with a quoted string:
38+
example sub "quoted string"
39+
40+
# Mix and match:
41+
example sub "multi-word quoted string" --name "another quoted string" -a
42+
43+
# Multi-line:
44+
ENV_A=0 ENV_B=0 ENV_C=0 \
45+
CERT_FILE=/path/to/chain.pem KEY_FILE=/path/to/key.pem \
46+
example sub "quoted argument"
47+
48+
# Run a subcommand's subcommand with an argument:
49+
example sub another args --flag
50+
`,
51+
52+
RunE: func(c *cobra.Command, _ []string) error {
53+
if eerr {
54+
return errors.New("we have an error")
55+
}
56+
c.Println("You ran the root command. Now try --help.")
57+
return nil
58+
},
59+
}
60+
cmd.PersistentFlags().StringVarP(&foo, "surname", "s", "doe", "Your surname")
61+
cmd.Flags().StringVar(&foo, "name", "jane", "Your name")
62+
cmd.Flags().DurationVar(&d, "duration", 0, "Time since your last commit")
63+
cmd.Flags().IntVar(&bar, "age", 0, "Your age")
64+
cmd.Flags().Float64Var(&baz, "idk", 0.0, "I don't know")
65+
cmd.Flags().BoolP("async", "a", false, "Run async")
66+
cmd.Flags().BoolVarP(&eerr, "error", "e", false, "Makes the program exit with error")
67+
68+
_ = cmd.Flags().MarkHidden("age")
69+
_ = cmd.Flags().MarkHidden("duration")
70+
_ = cmd.Flags().MarkHidden("idk")
71+
_ = cmd.Flags().MarkHidden("error")
72+
73+
cmd.AddGroup(&cobra.Group{
74+
ID: "group1",
75+
Title: "My Group",
76+
})
77+
sub := &cobra.Command{
78+
Use: "sub [command] [flags] [args]",
79+
Short: "An example subcommand",
80+
GroupID: "group1",
81+
Example: `example sub some arguments --and-flags
82+
example sub another --thing`,
83+
Run: func(c *cobra.Command, _ []string) {
84+
c.Println("Ran the sub command!")
85+
},
86+
}
87+
cmd.AddCommand(sub)
88+
sub.AddCommand(&cobra.Command{
89+
Use: "another",
90+
Short: "another sub command",
91+
Example: `example sub another --foo=bar`,
92+
RunE: func(c *cobra.Command, _ []string) error {
93+
cmd.Println("Working...")
94+
select {
95+
case <-time.After(time.Second * 5):
96+
cmd.Println("Done!")
97+
case <-c.Context().Done():
98+
return c.Context().Err()
99+
}
100+
return nil
101+
},
102+
})
103+
104+
cmd.AddCommand(&cobra.Command{
105+
Use: "throw",
106+
Short: "Throws an error",
107+
GroupID: "group1",
108+
RunE: func(*cobra.Command, []string) error {
109+
return errors.New("a super long error string that is meant to test the error handling in fang. It should be long enough to wrap around and test the error styling and formatting capabilities of fang. This is a test to see how well fang handles long error messages and whether it can display them properly without breaking the layout or causing any issues")
110+
},
111+
})
112+
113+
// This is where the magic happens.
114+
if err := fang.Execute(
115+
context.Background(),
116+
cmd,
117+
fang.WithNotifySignal(os.Interrupt, os.Kill),
118+
); err != nil {
119+
os.Exit(1)
120+
}
121+
}

example/run

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
go build -o ./example/bin ./example/main.go
3+
./example/bin $* || true

0 commit comments

Comments
 (0)