Skip to content

Commit 3ff3ed8

Browse files
committed
initial work
0 parents  commit 3ff3ed8

9 files changed

Lines changed: 472 additions & 0 deletions

File tree

.circleci/config.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
version: 2.1
2+
executors:
3+
base:
4+
docker:
5+
- image: circleci/golang:1.12
6+
working_directory: /go/src/github.com/spatialcurrent/goprintenv
7+
jobs:
8+
pre_deps_golang:
9+
executor: base
10+
steps:
11+
- checkout
12+
- run: make deps_go
13+
- run: sudo chown -R circleci /go/src
14+
- save_cache:
15+
key: v1-go-src-{{ .Branch }}-{{ .Revision }}
16+
paths:
17+
- /go/src
18+
test_go:
19+
executor: base
20+
steps:
21+
- run: sudo chown -R circleci /go/src
22+
- restore_cache:
23+
keys:
24+
- v1-go-src-{{ .Branch }}-{{ .Revision }}
25+
- run: make deps_go_test
26+
- run: make test_go
27+
- run: make imports
28+
- run: git diff --exit-code
29+
build_cli:
30+
executor: base
31+
steps:
32+
- run: sudo chown -R circleci /go/src
33+
- restore_cache:
34+
keys:
35+
- v1-go-src-{{ .Branch }}-{{ .Revision }}
36+
- run: go get github.com/inconshreveable/mousetrap # for windows CLI builds
37+
- run: make build_cli
38+
- store_artifacts:
39+
path: bin
40+
destination: /
41+
workflows:
42+
main:
43+
jobs:
44+
- pre_deps_golang
45+
- test_go:
46+
requires:
47+
- pre_deps_golang
48+
- build_cli:
49+
requires:
50+
- pre_deps_golang

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
secret/
2+
bin/
3+
*.so
4+
*.h

AUTHORS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
goprintenv is maintained by Spatial Current, Inc.
2+
3+
Authors:
4+
5+
* Patrick Dufour (pjdufour)

CONTRIBUTING.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Contributing to goprintenv
2+
3+
## Contributor License Agreement
4+
5+
Thank you for your interest in contributing. You will first need to agree to the license. Simply post the following paragraph, with "your name" and "your github account" substituted as needed, to the first issue [#1](https://github.com/spatialcurrent/goprintenv/issues/1). Otherwise, you can email us [here](mailto:opensource@spatialcurrent.io?subject=CLA).
6+
7+
I, **< YOUR NAME > (< YOUR GITHUB ACCOUNT >)**, agree to the license terms. My contributions to this repo are granted to **Spatial Current, Inc.** under a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable license and/or copyright is transferred.
8+
9+
## Versioning
10+
11+
This program is released using semantic versioning.
12+
13+
- New flags that alter default behavior are major releases.
14+
- New flags that maintain the same default behavior are minor releases.
15+
- Upgrades of dependencies that don't alert default behavior are patch releases.
16+
17+
## Authors
18+
19+
See [AUTHORS](https://github.com/spatialcurrent/goprintenv/blob/master/AUTHORS) for a list of contributors.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Spatial Current, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# =================================================================
2+
#
3+
# Copyright (C) 2019 Spatial Current, Inc. - All Rights Reserved
4+
# Released as open source under the MIT License. See LICENSE file.
5+
#
6+
# =================================================================
7+
8+
ifdef GOPATH
9+
GCFLAGS=-trimpath=$(shell printenv GOPATH)/src
10+
else
11+
GCFLAGS=-trimpath=$(shell go env GOPATH)/src
12+
endif
13+
14+
LDFLAGS=-X main.gitBranch=$(shell git branch | grep \* | cut -d ' ' -f2) -X main.gitCommit=$(shell git rev-list -1 HEAD)
15+
16+
.PHONY: help
17+
help: ## Print the help documentation
18+
@grep -E '^[a-zA-Z0-9_-\]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
19+
20+
#
21+
# Dependencies
22+
#
23+
24+
.PHONY: deps_go
25+
deps_go: ## Install Go dependencies
26+
go get -d -t ./...
27+
28+
.PHONY: deps_go_test
29+
deps_go_test: ## Download Go dependencies for tests
30+
go get golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow # download shadow
31+
go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow # install shadow
32+
go get -u github.com/kisielk/errcheck # download and install errcheck
33+
go get -u github.com/client9/misspell/cmd/misspell # download and install misspell
34+
go get -u github.com/gordonklaus/ineffassign # download and install ineffassign
35+
go get -u honnef.co/go/tools/cmd/staticcheck # download and instal staticcheck
36+
go get -u golang.org/x/tools/cmd/goimports # download and install goimports
37+
38+
.PHONY: deps_arm
39+
deps_arm: ## Install dependencies to cross-compile to ARM
40+
# ARMv7
41+
apt-get install -y libc6-armel-cross libc6-dev-armel-cross binutils-arm-linux-gnueabi libncurses5-dev gcc-arm-linux-gnueabi g++-arm-linux-gnueabi
42+
# ARMv8
43+
apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
44+
45+
46+
#
47+
# Go building, formatting, testing, and installing
48+
#
49+
50+
.PHONY: fmt
51+
fmt: ## Format Go source code
52+
go fmt $$(go list ./... )
53+
54+
.PHONY: imports
55+
imports: ## Update imports in Go source code
56+
# If missing, install goimports with: go get golang.org/x/tools/cmd/goimports
57+
goimports -w $$(find . -iname '*.go')
58+
59+
.PHONY: vet
60+
vet: ## Vet Go source code
61+
go vet $$(go list ./...)
62+
63+
.PHONY: test_go
64+
test_go: ## Run Go tests
65+
bash scripts/test.sh
66+
67+
.PHONY: build
68+
build: build_cli ## Build all artifacts
69+
70+
.PHONY: install
71+
install: ## Install goprintenv on current platform
72+
go install -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" github.com/spatialcurrent/goprintenv
73+
74+
#
75+
# Command Line Programs
76+
#
77+
78+
bin/goprintenv_darwin_amd64: ## Build goprintenv for Darwin / amd64
79+
GOOS=darwin GOARCH=amd64 go build -o bin/goprintenv_darwin_amd64 -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" $$(go list ./...)
80+
81+
bin/goprintenv_linux_amd64: ## Build goprintenv for Linux / amd64
82+
GOOS=linux GOARCH=amd64 go build -o bin/goprintenv_linux_amd64 -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" $$(go list ./...)
83+
84+
bin/goprintenv_windows_amd64.exe: ## Build goprintenv for Windows / amd64
85+
GOOS=windows GOARCH=amd64 go build -o bin/goprintenv_windows_amd64.exe -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" $$(go list ./...)
86+
87+
bin/goprintenv_linux_arm64: ## Build goprintenv for Linux / arm64
88+
GOOS=linux GOARCH=arm64 go build -o bin/goprintenv_linux_arm64 -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" $$(go list ./...)
89+
90+
bin/goprintenv_linux_arm: ## Build goprintenv for Linux / arm
91+
GOOS=linux GOARCH=arm go build -o bin/goprintenv_linux_arm -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" $$(go list ./...)
92+
93+
.PHONY: build_cli
94+
build_cli: bin/goprintenv_darwin_amd64 bin/goprintenv_linux_amd64 bin/goprintenv_windows_amd64.exe bin/goprintenv_linux_arm bin/goprintenv_linux_arm64 ## Build command line programs
95+
96+
## Clean
97+
98+
.PHONY: clean
99+
clean: ## Clean artifacts
100+
rm -fr bin
101+
rm -fr dist

README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
[![CircleCI](https://circleci.com/gh/spatialcurrent/goprintenv/tree/master.svg?style=svg)](https://circleci.com/gh/spatialcurrent/goprintenv/tree/master) [![Go Report Card](https://goreportcard.com/badge/spatialcurrent/goprintenv)](https://goreportcard.com/report/spatialcurrent/goprintenv) [![GoDoc](https://godoc.org/github.com/spatialcurrent/goprintenv?status.svg)](https://godoc.org/github.com/spatialcurrent/goprintenv) [![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://github.com/spatialcurrent/goprintenv/blob/master/LICENSE)
2+
3+
# goprintenv
4+
5+
# Description
6+
7+
**goprintenv** is a super simple command line program for printing environment variables, including in custom formats. **goprintenv** supports the following operating systems and architectures. While **goprintenv** does not intend to be a drop-in replacement to the system `printenv` command, it aims to provide a similar command line usage and an enhanced capability.
8+
9+
**Platforms**
10+
11+
| GOOS | GOARCH |
12+
| ---- | ------ |
13+
| darwin | amd64 |
14+
| linux | amd64 |
15+
| windows | amd64 |
16+
| linux | arm64 |
17+
18+
# Installation
19+
20+
No installation is required. Just grab a [release](https://github.com/spatialcurrent/goprintenv/releases). You might want to rename your binary to just `goprintenv` (or `printenv`) for convenience.
21+
22+
If you do have go already installed, you can just run using `go run main.go` or install with `make install`
23+
24+
# Usage
25+
26+
See the usage below or the following examples.
27+
28+
```
29+
goprintenv is a super simple utility to print environment variables in a custom format. Supports: csv, bson, go, json, properties, tags, toml, tsv, yaml.
30+
31+
Usage:
32+
goprintenv [-f FORMAT] [flags] [variable]...
33+
34+
Flags:
35+
-f, --format string output format, one of: csv, bson, go, json, properties, tags, toml, tsv, yaml (default "properties")
36+
-h, --help help for goprintenv
37+
-0, --null use a NUL byte to end each line instead of a newline character
38+
-p, --pretty use pretty output format
39+
-r, --reversed if output is sorted, sort in reverse alphabetical order
40+
-s, --sorted sort output
41+
```
42+
43+
# Examples
44+
45+
**All Environment Variables**
46+
47+
```shell
48+
goprintenv -f json
49+
```
50+
51+
**Subset of Environment Variables**
52+
53+
`goprintenv` accepts a list of environment variables.
54+
55+
```shell
56+
goprintenv SHELL PATH
57+
```
58+
59+
**Subset of Environment Variables as Pretty JSON**
60+
61+
`goprintenv` accepts a list of environment variables and a custom format.
62+
63+
```shell
64+
goprintenv -f json -p SHELL PATH
65+
```
66+
67+
# Building
68+
69+
You can build all the released artifacts using `make build` or run the make target for a specific operating system and architecture.
70+
71+
# Testing
72+
73+
Run test using `bash scripts/test.sh` or `make test`, which runs unit tests, `go vet`, `go vet with shadow`, [errcheck](https://github.com/kisielk/errcheck), [ineffassign](https://github.com/gordonklaus/ineffassign), [staticcheck](https://staticcheck.io/), and [misspell](https://github.com/client9/misspell).
74+
75+
# Contributing
76+
77+
[Spatial Current, Inc.](https://spatialcurrent.io) is currently accepting pull requests for this repository. We'd love to have your contributions! Please see [Contributing.md](https://github.com/spatialcurrent/goprintenv/blob/master/CONTRIBUTING.md) for how to get started.
78+
79+
# License
80+
81+
This work is distributed under the **MIT License**. See **LICENSE** file.

0 commit comments

Comments
 (0)