方:命令行启动工具包
Fang, the CLI Starter Kit

原始链接: https://github.com/charmbracelet/fang

Fang是一个小型实验性的Go库,旨在简化Cobra应用程序的开发。它提供“内置电池”功能,通过视觉上吸引人的样式化帮助信息、使用页面和错误消息来增强用户体验。Fang自动管理`--version`标志,从构建信息或自定义版本中获取版本号。它使用Mango(基于roff)简化man页的生成,比Cobra默认方法生成的man页更简洁,尤其对于那些子命令较少的简单程序,避免了过多的单个命令man页。Fang还包含shell自动补全功能的生成。该库具有主题化功能,允许自定义外观和风格。错误发生时静默输出使用信息,提高了可用性。集成Fang非常简单:只需将你的根`*cobra.Command`传递给`fang.Execute`即可。它是开源的(MIT许可),并且是Charm生态系统的一部分。Mango生成单个man页,更适合于子命令较少的项目。

这个Hacker News帖子讨论了Charmbracelet基于Go语言的CLI入门工具包Fang。最初的评论将其与Rust的等效工具rust-starter进行了比较,并指出了交叉编译的挑战。Go更简单的交叉编译和诸如Goreleaser之类的工具被认为是优势。 Charmbracelet的贡献者也参与了讨论,提到了他们使用Goreleaser,并且Fang的作者也创建了GoReleaser。一个关键点是更倾向于简单纯文本的CLI输出,而不是“过于美观”的界面,强调易用性和可脚本性。 人们担心包括对齐、换行问题以及更花哨的CLI工具中潜在的bug。一个好的折中方案是在stdout不是tty时输出纯文本。 还提到了Cobra的替代方案,例如kong。
相关文章

原文

Charm Fang

Latest Release GoDoc Build Status

The CLI starter kit. A small, experimental library for batteries-included Cobra applications.

fang-02

  • Fancy output: fully styled help and usage pages
  • Fancy errors: fully styled errors
  • Automatic --version: set it to the build info, or a version of your choice
  • Manpages: Adds a hidden man command to generate manpages using mango1
  • Completions: Adds a completion command to generate shell completions
  • Themeable: use the built-in theme, or make your own
  • UX: Silent usage output (help is not shown after a user error)

To use it, invoke fang.Execute passing your root *cobra.Command:

package main

import (
	"os"

	"github.com/charmbracelet/fang"
	"github.com/spf13/cobra"
)

func main() {
	cmd := &cobra.Command{
		Use:   "example",
		Short: "A simple example program!",
	}
	if err := fang.Execute(context.TODO(), cmd); err != nil {
		os.Exit(1)
	}
}

That's all there is to it!

See contributing.

We’d love to hear your thoughts on this project. Feel free to drop us a note!

MIT


Part of Charm.

The Charm logo

Charm热爱开源 • Charm loves open source

  1. Default cobra man pages generates one man page for each command. This is generally fine for programs with a lot of sub commands, like git, but its an overkill for smaller programs. Mango also uses roff directly instead of converting from markdown, so it should render better looking man pages.

联系我们 contact @ memedata.com