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="865" alt="fang-02" src="https://github.com/user-attachments/assets/7f68ec3f-2b42-4188-a750-7e2808696132" />
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 "os"
49
50 "github.com/charmbracelet/fang"
51 "github.com/spf13/cobra"
52)
53
54func main() {
55 cmd := &cobra.Command{
56 Use: "example",
57 Short: "A simple example program!",
58 }
59 if err := fang.Execute(context.TODO(), cmd); err != nil {
60 os.Exit(1)
61 }
62}
63```
64
65That's all there is to it!
66
67## Contributing
68
69See [contributing][contribute].
70
71[contribute]: https://github.com/charmbracelet/fang/contribute
72
73## Feedback
74
75We’d love to hear your thoughts on this project. Feel free to drop us a note!
76
77- [Twitter](https://twitter.com/charmcli)
78- [Discord](https://charm.sh/chat)
79- [The Fediverse](https://mastodon.social/@charmcli)
80
81## License
82
83[MIT](https://github.com/charmbracelet/gum/raw/main/LICENSE)
84
85---
86
87Part of [Charm](https://charm.sh).
88
89<a href="https://charm.sh/"><img alt="The Charm logo" src="https://stuff.charm.sh/charm-badge.jpg" width="400" /></a>
90
91Charm热爱开源 • Charm loves open source