Skip to content

Commit 0683e07

Browse files
committed
Merge pull request #29 from jingweno/show_version
Show version
2 parents 4a1cd45 + f6ba4bb commit 0683e07

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

main.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,17 @@ type ccatCmd struct {
1717
Color string
1818
ColorCodes mapValue
1919
ShowPalette bool
20+
ShowVersion bool
2021
}
2122

2223
func (c *ccatCmd) Run(cmd *cobra.Command, args []string) {
24+
stdout := colorable.NewColorableStdout()
25+
26+
if c.ShowVersion {
27+
displayVersion(stdout)
28+
return
29+
}
30+
2331
var colorPalettes ColorPalettes
2432
if c.BG == "dark" {
2533
colorPalettes = DarkColorPalettes
@@ -66,7 +74,6 @@ Value of color can be %s
6674
args = []string{readFromStdin}
6775
}
6876

69-
stdout := colorable.NewColorableStdout()
7077
for _, arg := range args {
7178
err := CCat(arg, printer, stdout)
7279
if err != nil {
@@ -110,6 +117,7 @@ Examples:
110117
rootCmd.PersistentFlags().StringVarP(&ccatCmd.Color, "color", "C", "auto", `colorize the output; value can be "never", "always" or "auto"`)
111118
rootCmd.PersistentFlags().VarP(&ccatCmd.ColorCodes, "color-code", "G", `set color codes`)
112119
rootCmd.PersistentFlags().BoolVarP(&ccatCmd.ShowPalette, "palette", "", false, `show color palettes`)
120+
rootCmd.PersistentFlags().BoolVarP(&ccatCmd.ShowVersion, "version", "v", false, `show version`)
113121

114122
rootCmd.Execute()
115123
}

version.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
package main
22

3-
const Version = "0.1.0"
3+
import (
4+
"fmt"
5+
"io"
6+
)
7+
8+
const Version = "1.0.0"
9+
10+
func displayVersion(w io.Writer) {
11+
fmt.Fprintf(w, "ccat v%s\n", Version)
12+
}

0 commit comments

Comments
 (0)