方:命令行启动工具包
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 最新 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 Fang,CLI 启动工具包 (github.com/charmbracelet) 12 分,来自 bewuethr,1 小时前 | 隐藏 | 过去 | 收藏 | 讨论 考虑申请 YC 2025 秋季批次!申请截止日期为 8 月 4 日 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系我们 搜索:
相关文章

原文

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