File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,20 +2,24 @@ package main
22
33import (
44 "context"
5+ _ "embed"
56 "log"
67 "os"
78 "os/signal"
89
910 "github.com/openclosed-dev/docksider/internal/cmd"
1011)
1112
13+ //go:embed version.txt
14+ var version string
15+
1216func main () {
1317
1418 log .SetFlags (0 )
1519
1620 ctx , cancel := signal .NotifyContext (context .Background (), os .Interrupt )
1721 defer cancel ()
18- if err := cmd .NewRootCmd ().ExecuteContext (ctx ); err != nil {
22+ if err := cmd .NewRootCmd (version ).ExecuteContext (ctx ); err != nil {
1923 cancel ()
2024 os .Exit (1 )
2125 }
Original file line number Diff line number Diff line change 1+ 0.1.0
Original file line number Diff line number Diff line change 11package cmd
22
33import (
4+ "strings"
5+
46 "github.com/openclosed-dev/docksider/internal/cmd/image"
57 "github.com/spf13/cobra"
68)
79
8- func NewRootCmd () * cobra.Command {
10+ func NewRootCmd (version string ) * cobra.Command {
911
1012 const (
1113 use = "docksider [OPTIONS] COMMAND [ARG...]"
1214 short = "A Docker-style CLI for pulling and pushing images directly to container registries"
1315 )
1416
17+ version = strings .TrimSpace (version )
18+
1519 root := & cobra.Command {
1620 Use : use ,
1721 Short : short ,
22+ Version : version ,
1823 SilenceUsage : true ,
1924 SilenceErrors : false ,
2025
@@ -33,6 +38,7 @@ func NewRootCmd() *cobra.Command {
3338 image .NewImagesCmd (),
3439 image .NewPullCmd (),
3540 image .NewPushCmd (),
41+ NewVersionCmd (version ),
3642 )
3743
3844 return root
Original file line number Diff line number Diff line change 1+ package cmd
2+
3+ import (
4+ "fmt"
5+
6+ "github.com/spf13/cobra"
7+ )
8+
9+ func NewVersionCmd (version string ) * cobra.Command {
10+
11+ const (
12+ use = "version"
13+ short = "Print the version"
14+ )
15+
16+ cmd := & cobra.Command {
17+ Use : use ,
18+ Short : short ,
19+ RunE : func (cmd * cobra.Command , _ []string ) error {
20+ fmt .Fprintln (cmd .OutOrStdout (), version )
21+ return nil
22+ },
23+ DisableFlagsInUseLine : true ,
24+ }
25+
26+ return cmd
27+ }
You can’t perform that action at this time.
0 commit comments