Skip to content

Commit 3e9f52d

Browse files
committed
add: an option for version
1 parent e8f6983 commit 3e9f52d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

cmd/root.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,15 @@ var rootCmd = &cobra.Command{
1717
Use: "gcstree <bucket>",
1818
Short: "A tree command for Google Cloud Storage",
1919
Long: ``,
20-
Args: cobra.MinimumNArgs(1),
2120
Run: func(cmd *cobra.Command, args []string) {
21+
if ok, _ := cmd.Flags().GetBool("version"); ok {
22+
fmt.Printf("gcstree v%s\n", internal.GCSTREE_VERSION)
23+
os.Exit(0)
24+
}
25+
if len(args) == 0 {
26+
cmd.Help()
27+
os.Exit(0)
28+
}
2229
bucket := args[0]
2330
var ctx context.Context = context.Background()
2431
gcsTree, err := internal.NewGCSTree(ctx, bucket)
@@ -39,3 +46,7 @@ func Execute() {
3946
os.Exit(1)
4047
}
4148
}
49+
50+
func init() {
51+
rootCmd.Flags().BoolP("version", "v", false, "show the gcstree version")
52+
}

internal/gcstree.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"google.golang.org/api/iterator"
1010
)
1111

12+
const GCSTREE_VERSION = "0.0.1"
13+
1214
type GCSTree struct {
1315
bucket string
1416
folder string

0 commit comments

Comments
 (0)