Skip to content
This repository was archived by the owner on Aug 24, 2024. It is now read-only.

Commit 25114f9

Browse files
committed
Add version command
This commit adds a command that allows the user to display the version of git-bug-migration.
1 parent d2394eb commit 25114f9

File tree

3 files changed

+43
-48
lines changed

3 files changed

+43
-48
lines changed

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ GIT_COMMIT:=$(shell git rev-list -1 HEAD)
44
GIT_LAST_TAG:=$(shell git describe --abbrev=0 --tags)
55
GIT_EXACT_TAG:=$(shell git name-rev --name-only --tags HEAD)
66

7-
LDFLAGS:=-X 'main.GitCommit=${GIT_COMMIT}' \
8-
-X 'main.GitLastTag=${GIT_LAST_TAG}' \
9-
-X 'main.GitExactTag=${GIT_EXACT_TAG}'
7+
COMMANDS_PATH:=github.com/MichaelMure/git-bug-migration/commands
8+
LDFLAGS:=-X '${COMMANDS_PATH}.GitCommit=${GIT_COMMIT}' \
9+
-X '${COMMANDS_PATH}.GitLastTag=${GIT_LAST_TAG}' \
10+
-X '${COMMANDS_PATH}.GitExactTag=${GIT_EXACT_TAG}'
1011

1112
build:
1213
go build -ldflags "$(LDFLAGS)" .

commands/migrate.go

Lines changed: 0 additions & 43 deletions
This file was deleted.

commands/root.go

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

1617
const 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
2151
var 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

Comments
 (0)