Skip to content

Commit

Permalink
Add example to help
Browse files Browse the repository at this point in the history
  • Loading branch information
owenthereal committed May 28, 2015
1 parent 1453bf6 commit 5102ece
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

0 comments on commit 5102ece

Please sign in to comment.