Skip to content

Commit

Permalink
Improve version string
Browse files Browse the repository at this point in the history
  • Loading branch information
jimschubert committed Feb 24, 2020
1 parent a294d12 commit 47c16c1
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 3 deletions.
154 changes: 154 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ossify
dist/

# Created by https://www.gitignore.io/api/go,intellij,linux,osx
# Edit at https://www.gitignore.io/?templates=go,intellij,linux,osx
Expand Down Expand Up @@ -146,3 +147,156 @@ Temporary Items
# End of https://www.gitignore.io/api/go,intellij,linux,osx

.releases/
### Linux template
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### macOS template
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Vim template
# Swap
[._]*.s[a-v][a-z]
!*.svg # comment out if you don't need vector files
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]

# Session
Session.vim
Sessionx.vim

# Temporary
.netrwhist
*~
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~

### Go template
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

4 changes: 4 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ before:
builds:
- env:
- CGO_ENABLED=0
# Custom ldflags templates.
# Default is `-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser`.
ldflags:
- -s -w -X github.com/jimschubert/ossify/config.Version={{.Version}} -X github.com/jimschubert/ossify/config.Commit={{.Commit}} -X github.com/jimschubert/ossify/config.Date={{.Date}} -X main.builtBy=goreleaser
archives:
- replacements:
darwin: Darwin
Expand Down
10 changes: 7 additions & 3 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/jimschubert/ossify/config"
"github.com/spf13/cobra"
"strings"
)

func init() {
Expand All @@ -14,8 +15,11 @@ var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of ossify",
Run: func(cmd *cobra.Command, args []string) {
// TODO: consider using goxc to set version on build.
// see https://sbstjn.com/create-golang-cli-application-with-cobra-and-goxc.html
fmt.Printf("ossify %s\n", config.Version)
// Version string can be tested with:
// goreleaser release --skip-publish --snapshot --rm-dist
var str strings.Builder
str.WriteString(fmt.Sprintf("ossify %s (%s)\n", config.Version, config.Commit))
str.WriteString(fmt.Sprintf("Built: %s", config.Date))
fmt.Println(str.String())
},
}
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ var DefaultConfig = Config{
}

var Version = "0.1"
var Commit = "n/a"
var Date = "n/a"

var configName = "settings.json"
//noinspection GoNameStartsWithPackageName
var ConfigManager *Manager
Expand Down

0 comments on commit 47c16c1

Please sign in to comment.