Skip to content

Commit

Permalink
Add version command
Browse files Browse the repository at this point in the history
  • Loading branch information
ipmb committed Jan 5, 2021
1 parent c36a629 commit f3c4dd3
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ builds:
- linux
- windows
- darwin
ldflags:
- -X github.com/lincolnloop/apppack/version.BuildDate={{ .Date }}
- -X github.com/lincolnloop/apppack/version.Version={{ .Version }}
- -X github.com/lincolnloop/apppack/version.Commit={{ .ShortCommit }}
- -X github.com/lincolnloop/apppack/version.Environment=production
archives:
- replacements:
darwin: Darwin
Expand Down
41 changes: 41 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright © 2021 NAME HERE <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
"fmt"

"github.com/lincolnloop/apppack/version"
"github.com/spf13/cobra"
)

// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "show the version of the apppack command",
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {
if version.Environment != "production" {
fmt.Println(version.Environment)
} else {
fmt.Println(version.Version)
}
},
}

func init() {
rootCmd.AddCommand(versionCmd)
}
8 changes: 8 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package version

import "time"

var BuildDate = time.Now().String()
var Version = "<version>"
var Commit = "<commit>"
var Environment = "development"

0 comments on commit f3c4dd3

Please sign in to comment.