Skip to content

Commit

Permalink
refactor: code example with compile time variables
Browse files Browse the repository at this point in the history
  • Loading branch information
joseluisq committed Nov 10, 2020
1 parent 2a3de56 commit 1a440a8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 22 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
BUILD_TIME ?= $(shell date -u '+%Y-%m-%dT%H:%m:%S')

install:
@go version
@go get -v golang.org/x/lint/golint
Expand All @@ -11,7 +13,9 @@ test:
.PHONY: test

build:
@go build -v -ldflags "-s -w -X main.version=0.0.0" -a -o bin/cline ./examples
@go build -v \
-ldflags "-s -w -X 'main.version=0.0.0' -X 'main.buildTime=$(BUILD_TIME)'" \
-a -o bin/cline ./examples
.PHONY: build

coverage:
Expand Down
54 changes: 37 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ WIP project under **active** development.

## Usage

API definition example:

```go
package main

Expand All @@ -28,10 +30,18 @@ import (
cli "github.com/joseluisq/cline"
)

// App version and build time values passed at compile time
var (
versionNumber string = "devel"
buildTime string
)

func main() {
app := cli.New()
app.Name = "enve"
app.Summary = "Run a program in a modified environment using .env files"
app.Version = versionNumber
app.BuildTime = buildTime
app.Flags = []cli.Flag{
cli.FlagString{
Name: "file",
Expand Down Expand Up @@ -90,26 +100,36 @@ func main() {
os.Exit(1)
}
}
```

// OUTPUT:
//
// go run examples/main.go -h
// NAME: enve [OPTIONS] COMMAND

// Run a program in a modified environment using .env files

// OPTIONS:
// --file Load environment variables from a file path
// --verbose Enable more verbose info
// --version Prints version information
// --help Prints help information

// COMMANDS:
// info Show command information

// Run 'enve COMMAND --help' for more information on a command
Output example:

```sh
$ go run examples/main.go -h
# NAME: enve [OPTIONS] COMMAND
#
# Run a program in a modified environment using .env files
#
# OPTIONS:
# --file Load environment variables from a file path
# --verbose Enable more verbose info
# --version Prints version information
# --help Prints help information
#
# COMMANDS:
# info Show command information
#
# Run 'enve COMMAND --help' for more information on a command

$ go run examples/main.go -v
# Version: 0.0.0
# Go version: go1.15.4
# Built: 2020-11-10T21:11:36
# OS/Arch: linux/amd64
```

More details on [examples/main.go](./examples/main.go)

## Contributions

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in current work by you, as defined in the Apache-2.0 license, shall be dual licensed as described below, without any additional terms or conditions.
Expand Down
9 changes: 5 additions & 4 deletions examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ import (
cli "github.com/joseluisq/cline"
)

// Application version values
// App version and build time values passed at compile time
// See `Makefile` > build
var (
versionNumber string = "devel"
buildTime string
version string = "devel"
buildTime string
)

func main() {
app := cli.New()
app.Name = "enve"
app.Summary = "Run a program in a modified environment using .env files"
app.Version = versionNumber
app.Version = version
app.BuildTime = buildTime
app.Flags = []cli.Flag{
cli.FlagString{
Expand Down

0 comments on commit 1a440a8

Please sign in to comment.