Skip to content
This repository has been archived by the owner on Nov 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #15 from tfmigrator/chore/embed-version
Browse files Browse the repository at this point in the history
chore: embed version and remove constant package
  • Loading branch information
suzuki-shunsuke authored Oct 24, 2021
2 parents 67a5d08 + ba113f3 commit eb57453
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 65 deletions.
4 changes: 3 additions & 1 deletion .cmdx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ tasks:
short: r
description: release the new version
usage: release the new version
script: "bash scripts/release.sh {{.version}}"
script: |
git tag "{{.version}}"
git push origin "{{.version}}"
args:
- name: version
required: true
Expand Down
11 changes: 11 additions & 0 deletions cmd/tfmigrator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import (
"github.com/tfmigrator/cli/pkg/cli"
)

var (
version = ""
commit = "" //nolint:gochecknoglobals
date = "" //nolint:gochecknoglobals
)

func main() {
if err := core(); err != nil {
logrus.Fatal(err)
Expand All @@ -20,6 +26,11 @@ func core() error {
Stdin: os.Stdin,
Stdout: os.Stdout,
Stderr: os.Stderr,
LDFlags: &cli.LDFlags{
Version: version,
Commit: commit,
Date: date,
},
}
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
defer stop()
Expand Down
20 changes: 15 additions & 5 deletions pkg/cli/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,31 @@ import (
"context"
"io"

"github.com/tfmigrator/cli/pkg/constant"
"github.com/urfave/cli/v2"
)

type LDFlags struct {
Version string
Commit string
Date string
}

func (flags *LDFlags) AppVersion() string {
return flags.Version + " (" + flags.Commit + ")"
}

type Runner struct {
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
LDFlags *LDFlags
}

func (runner *Runner) Run(ctx context.Context, args ...string) error {
app := cli.App{
Name: "tfmigrator",
Usage: "Migrate Terraform Configuration and State. https://github.com/tfmigrator/cli",
Version: constant.Version,
Version: runner.LDFlags.AppVersion(),
Commands: []*cli.Command{
{
Name: "run",
Expand Down
7 changes: 0 additions & 7 deletions pkg/constant/version.go

This file was deleted.

52 changes: 0 additions & 52 deletions scripts/release.sh

This file was deleted.

0 comments on commit eb57453

Please sign in to comment.