@@ -9,13 +9,43 @@ import (
99
1010 "github.com/spf13/cobra"
1111
12+ mg1 "github.com/MichaelMure/git-bug-migration/migration1"
1213 mg1b "github.com/MichaelMure/git-bug-migration/migration1/bug"
1314 mg1r "github.com/MichaelMure/git-bug-migration/migration1/repository"
1415)
1516
1617const rootCommandName = "git-bug-migration"
1718
18- var repo mg1r.ClockedRepo
19+ var (
20+ repo mg1r.ClockedRepo
21+
22+ // These variables are initialized externally during the build. See the Makefile.
23+ GitCommit = ""
24+ GitLastTag = ""
25+ GitExactTag = ""
26+
27+ rootCmdShowVersion bool
28+ )
29+
30+ func runRootCmd (_ * cobra.Command , args []string ) error {
31+ if rootCmdShowVersion {
32+ fmt .Printf (version ())
33+ return nil
34+ }
35+
36+ return mg1 .Migrate01 (repo )
37+ }
38+
39+ func version () string {
40+ if GitExactTag == "undefined" {
41+ GitExactTag = ""
42+ }
43+ version := GitLastTag
44+ if GitExactTag == "" {
45+ version = fmt .Sprintf ("%s-dev-%.10s" , version , GitCommit )
46+ }
47+ return version
48+ }
1949
2050// RootCmd represents the base command when called without any subcommands
2151var RootCmd = & cobra.Command {
@@ -30,7 +60,7 @@ var RootCmd = &cobra.Command{
3060 // even if we just display the help. This is to make sure that we check
3161 // the repository and give the user early feedback.
3262 PreRunE : loadRepo ,
33- RunE : runMigrateCmd ,
63+ RunE : runRootCmd ,
3464
3565 SilenceUsage : true ,
3666 DisableAutoGenTag : true ,
@@ -67,3 +97,10 @@ func Execute() {
6797 os .Exit (1 )
6898 }
6999}
100+
101+ func init () {
102+ RootCmd .Flags ().SortFlags = false
103+
104+ RootCmd .Flags ().BoolVarP (& rootCmdShowVersion , "version" , "v" , false ,
105+ "Show the version of the migration tool. This will not run the tool." )
106+ }
0 commit comments