README.md

 1# Fang
 2
 3<p>
 4    <img width="485" alt="Charm Fang" src="https://github.com/user-attachments/assets/3f34ea01-3750-4760-beb2-a1b700e110f5">
 5</p>
 6<p>
 7    <a href="https://github.com/charmbracelet/fang/releases"><img src="https://img.shields.io/github/release/charmbracelet/fang.svg" alt="Latest Release"></a>
 8    <a href="https://pkg.go.dev/github.com/charmbracelet/fang?tab=doc"><img src="https://godoc.org/github.com/charmbracelet/fang?status.svg" alt="GoDoc"></a>
 9    <a href="https://github.com/charmbracelet/fang/actions"><img src="https://github.com/charmbracelet/fang/workflows/build/badge.svg" alt="Build Status"></a>
10</p>
11
12The CLI starter kit. A small, experimental library for batteries-included [Cobra][cobra] applications.
13
14<p>
15    <img width="859" alt="The Charm Fang mascot and title treatment" src="https://github.com/user-attachments/assets/5c35e1fa-9577-4f81-a879-3ddb4d4a43f0" />
16</p>
17
18## Features
19
20- **Fancy output**: fully styled help and usage pages
21- **Fancy errors**: fully styled errors
22- **Automatic `--version`**: set it to the [build info][info], or a version of your choice
23- **Manpages**: Adds a hidden `man` command to generate _manpages_ using
24  [mango][][^1]
25- **Completions**: Adds a `completion` command to generate shell completions
26- **Themeable**: use the built-in theme, or make your own
27- **UX**: Silent `usage` output (help is not shown after a user error)
28
29[info]: https://pkg.go.dev/runtime/debug#BuildInfo
30[cobra]: https://github.com/spf13/cobra
31[mango]: https://github.com/muesli/mango
32
33[^1]:
34    Default cobra man pages generates one man page for each command. This is
35    generally fine for programs with a lot of sub commands, like git, but its an
36    overkill for smaller programs.
37    Mango also uses _roff_ directly instead of converting from markdown, so it
38    should render better looking man pages.
39
40## Usage
41
42To use it, invoke `fang.Execute` passing your root `*cobra.Command`:
43
44```go
45package main
46
47import (
48	"context"
49	"os"
50
51	"github.com/charmbracelet/fang"
52	"github.com/spf13/cobra"
53)
54
55func main() {
56	cmd := &cobra.Command{
57		Use:   "example",
58		Short: "A simple example program!",
59	}
60	if err := fang.Execute(context.Background(), cmd); err != nil {
61		os.Exit(1)
62	}
63}
64```
65
66That's all there is to it!
67
68## Contributing
69
70See [contributing][contribute].
71
72[contribute]: https://github.com/charmbracelet/fang/contribute
73
74## Feedback
75
76We’d love to hear your thoughts on this project. Feel free to drop us a note!
77
78- [Twitter](https://twitter.com/charmcli)
79- [Discord](https://charm.sh/chat)
80- [The Fediverse](https://mastodon.social/@charmcli)
81
82## License
83
84[MIT](https://github.com/charmbracelet/gum/raw/main/LICENSE)
85
86---
87
88Part of [Charm](https://charm.sh).
89
90<a href="https://charm.sh/"><img alt="The Charm logo" src="https://stuff.charm.sh/charm-badge.jpg" width="400" /></a>
91
92Charm热爱开源 • Charm loves open source