Skip to content

Commit

Permalink
Merge pull request #52 from inovex/feat-add-version-command
Browse files Browse the repository at this point in the history
feat: add version flag
  • Loading branch information
Alexander Huck authored Aug 10, 2023
2 parents d2f799e + 091edf6 commit 63c2516
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ jobs:
go-version: ${{ env.GO_VERSION }}
- uses: actions/checkout@v3
- run: go mod vendor
- run: go build -mod=vendor -ldflags "-X 'main.Version=${{ github.event.base_ref }}' -extldflags '-static'" -o calendarsync cmd/calendarsync/main.go
- run: go build -mod=vendor -ldflags "-X 'main.Version=${{ github.ref_name }}' -extldflags '-static'" -o calendarsync cmd/calendarsync/main.go
2 changes: 2 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ builds:
- env:
- CGO_ENABLED=0
dir: ./cmd/calendarsync
ldflags:
- -X 'main.Version={{.Version}}'
goos:
- linux
- windows
Expand Down
25 changes: 19 additions & 6 deletions cmd/calendarsync/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,20 @@ const (
flagClean = "clean"
flagDryRun = "dry-run"
flagPort = "port"
flagVersion = "version"
)

var (
// The following vars are set during linking
// Version is the version from which the binary was built.
Version string
// BuildTime is the timestamp of building the binary.
BuildTime string
)

func main() {
app := &cli.App{
Name: "CalendarSync",
Usage: "Stateless calendar sync across providers",
Description: fmt.Sprintf("Version %s - Build date %s", Version, BuildTime),
Description: fmt.Sprintf("Version: %s", Version),
Flags: []cli.Flag{
&cli.StringFlag{
Name: flagLogLevel,
Expand All @@ -49,9 +48,8 @@ func main() {
Value: "sync.yaml",
},
&cli.StringFlag{
Name: flagStorageEncryptionKey,
Usage: "encryption string",
Required: true,
Name: flagStorageEncryptionKey,
Usage: "encryption string",
},
&cli.BoolFlag{
Name: flagClean,
Expand All @@ -63,6 +61,11 @@ func main() {
Usage: "This flag helps you see which events would get created, updated or deleted without actually doing these operations",
Value: false,
},
&cli.BoolFlag{
Name: flagVersion,
Usage: "shows the version of CalendarSync",
Value: false,
},
&cli.UintFlag{
Name: flagPort,
Usage: "set manual free port for the authentication process",
Expand All @@ -86,15 +89,25 @@ func main() {
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}

}

func Run(c *cli.Context) error {
if c.Bool(flagVersion) {
fmt.Println("Version:", Version)
os.Exit(0)
}

cfg, err := config.NewFromFile(c.String(flagConfigFilePath))
if err != nil {
return err
}
log.Info("loaded config file", "path", cfg.Path)

if len(c.String(flagStorageEncryptionKey)) == 0 {
return fmt.Errorf("flag --storage-encryption-key needs to be set")
}

startTime, err := models.TimeFromConfig(cfg.Sync.StartTime)
if err != nil {
return err
Expand Down

0 comments on commit 63c2516

Please sign in to comment.