-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ccd36be
Showing
10 changed files
with
511 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Build output | ||
go-project | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Common | ||
.DS_Store | ||
.idea | ||
*.log | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
SHELL = /bin/bash | ||
|
||
APP_NAME = go-project | ||
VERSION := $(shell git describe --always --tags) | ||
GIT_COMMIT = $(shell git rev-parse HEAD) | ||
BUILD_DATE = $(shell date '+%Y-%m-%d-%H:%M:%S') | ||
|
||
.PHONY: default | ||
default: help | ||
|
||
.PHONY: help | ||
help: | ||
@echo 'Make commands for ${APP_NAME}:' | ||
@echo | ||
@echo 'Usage:' | ||
@echo ' make build Compile the project.' | ||
@echo ' make run ARGS= Run with supplied arguments.' | ||
@echo ' make test Run tests on a compiled project.' | ||
@echo ' make clean Clean the directory tree.' | ||
|
||
@echo | ||
|
||
.PHONY: build | ||
build: | ||
@echo "Building ${APP_NAME} ${VERSION}" | ||
go build -ldflags "-w -X github.com/zackijack/go-project/internal/version.Version=${VERSION} -X github.com/zackijack/go-project/internal/version.GitCommit=${GIT_COMMIT} -X github.com/zackijack/go-project/internal/version.BuildDate=${BUILD_DATE}" -o ${APP_NAME} | ||
|
||
.PHONY: run | ||
run: build | ||
@echo "Running ${APP_NAME} ${VERSION}" | ||
bin/${APP_NAME} ${ARGS} | ||
|
||
.PHONY: test | ||
test: | ||
@echo "Testing ${APP_NAME} ${VERSION}" | ||
go mod tidy | ||
go test ./... | ||
|
||
.PHONY: clean | ||
clean: | ||
@echo "Removing ${APP_NAME} ${VERSION}" | ||
@test ! -e bin/${APP_NAME} || rm bin/${APP_NAME} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# go-project | ||
Go project template |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
const completionDesc = ` | ||
To load completions: | ||
Bash: | ||
$ source <(go-project completion bash) | ||
# To load completions for each session, execute once: | ||
Linux: | ||
$ go-project completion bash > /etc/bash_completion.d/go-project | ||
MacOS: | ||
$ go-project completion bash > /usr/local/etc/bash_completion.d/go-project | ||
Zsh: | ||
# If shell completion is not already enabled in your environment you will need | ||
# to enable it. You can execute the following once: | ||
$ echo "autoload -U compinit; compinit" >> ~/.zshrc | ||
# To load completions for each session, execute once: | ||
$ go-project completion zsh > "${fpath[1]}/_go-project" | ||
# You will need to start a new shell for this setup to take effect. | ||
Fish: | ||
$ go-project completion fish | source | ||
# To load completions for each session, execute once: | ||
$ go-project completion fish > ~/.config/fish/completions/go-project.fish | ||
` | ||
|
||
var completionCmd = &cobra.Command{ | ||
Use: "completion [bash|zsh|fish|powershell]", | ||
Short: "Generate completion script", | ||
Long: completionDesc, | ||
DisableFlagsInUseLine: true, | ||
ValidArgs: []string{"bash", "zsh", "fish", "powershell"}, | ||
Args: cobra.ExactValidArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
switch args[0] { | ||
case "bash": | ||
cmd.Root().GenBashCompletion(os.Stdout) | ||
case "zsh": | ||
cmd.Root().GenZshCompletion(os.Stdout) | ||
case "fish": | ||
cmd.Root().GenFishCompletion(os.Stdout, true) | ||
case "powershell": | ||
cmd.Root().GenPowerShellCompletion(os.Stdout) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(completionCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// rootCmd represents the base command when called without any subcommands | ||
var rootCmd = &cobra.Command{ | ||
Use: "go-project", | ||
Short: "Go project template", | ||
} | ||
|
||
// Execute adds all child commands to the root command and sets flags appropriately. | ||
// This is called by main.main(). It only needs to happen once to the rootCmd. | ||
func Execute() { | ||
if err := rootCmd.Execute(); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func init() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/zackijack/go-project/internal/version" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const versionDesc = ` | ||
Showing who exactly go-project is. | ||
This will print a representation profile of go-project. | ||
The output will look something like this: | ||
Version: v1.0.0 | ||
Git Commit: ff52399e51bb880526e9cd0ed8386f6433b74da1 | ||
Build Date: 2020-07-27-17:07:02 | ||
Go Version: go1.14.6 | ||
OS Arch: darwin amd64 | ||
- Version is the semantic version of the release. | ||
- Git Commit is the SHA for the commit that this version was built from. | ||
- Build Date is the date when the application was built. | ||
- Go Version is the version of the Go compiler used. | ||
- OS Arch is the version of the operating system and architecture was built for. | ||
` | ||
|
||
var versionCmd = &cobra.Command{ | ||
Use: "version", | ||
Short: "Reveal go-project personal information", | ||
Long: versionDesc, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("Version:", version.Version) | ||
fmt.Println("Git Commit:", version.GitCommit) | ||
fmt.Println("Build Date:", version.BuildDate) | ||
fmt.Println("Go Version:", version.GoVersion) | ||
fmt.Println("OS Arch:", version.OsArch) | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(versionCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/zackijack/go-project | ||
|
||
go 1.16 | ||
|
||
require github.com/spf13/cobra v1.1.3 |
Oops, something went wrong.