Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add version flag #52

Merged
merged 5 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading