From 5102ecec55d390d0784fc4a635856db3f35964c9 Mon Sep 17 00:00:00 2001 From: Jingwen Owen Ou Date: Wed, 27 May 2015 17:41:47 -0700 Subject: [PATCH] Add example to help --- main.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 2a8cfd0..07ee45d 100644 --- a/main.go +++ b/main.go @@ -50,12 +50,30 @@ func (c *ccatCmd) Run(cmd *cobra.Command, args []string) { func main() { ccatCmd := &ccatCmd{} rootCmd := &cobra.Command{ - Use: "ccat [file ...]", + Use: "ccat [OPTION]... [FILE]...", Long: "Colorize FILE(s), or standard input, to standard output.", - Run: ccatCmd.Run, + Example: `$ ccat FILE1 FILE2 ... + $ ccat --bg=dark FILE1 FILE2 ... # dark background + $ ccat # read from standard input + $ curl https://raw.githubusercontent.com/jingweno/ccat/master/main.go | ccat`, + Run: ccatCmd.Run, } + usageTempl := `{{ $cmd := . }} +Usage: + {{.UseLine}} + +Flags: +{{.LocalFlags.FlagUsages}} +Using color is auto both by default and with --color=auto. With --color=auto, +ccat emits color codes only when standard output is connected to a terminal. + +Examples: + {{ .Example }}` + rootCmd.SetUsageTemplate(usageTempl) + rootCmd.PersistentFlags().StringVarP(&ccatCmd.BGFlag, "bg", "", "light", `Set to "light" or "dark" depending on the terminal's background`) rootCmd.PersistentFlags().StringVarP(&ccatCmd.ColorFlag, "color", "C", "auto", `colorize the output; value can be "never", "always" or "auto"`) + rootCmd.Execute() }