Skip to content

Commit

Permalink
initial work
Browse files Browse the repository at this point in the history
  • Loading branch information
pjdufour committed Jul 6, 2019
0 parents commit 3ff3ed8
Show file tree
Hide file tree
Showing 9 changed files with 472 additions and 0 deletions.
50 changes: 50 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
version: 2.1
executors:
base:
docker:
- image: circleci/golang:1.12
working_directory: /go/src/github.com/spatialcurrent/goprintenv
jobs:
pre_deps_golang:
executor: base
steps:
- checkout
- run: make deps_go
- run: sudo chown -R circleci /go/src
- save_cache:
key: v1-go-src-{{ .Branch }}-{{ .Revision }}
paths:
- /go/src
test_go:
executor: base
steps:
- run: sudo chown -R circleci /go/src
- restore_cache:
keys:
- v1-go-src-{{ .Branch }}-{{ .Revision }}
- run: make deps_go_test
- run: make test_go
- run: make imports
- run: git diff --exit-code
build_cli:
executor: base
steps:
- run: sudo chown -R circleci /go/src
- restore_cache:
keys:
- v1-go-src-{{ .Branch }}-{{ .Revision }}
- run: go get github.com/inconshreveable/mousetrap # for windows CLI builds
- run: make build_cli
- store_artifacts:
path: bin
destination: /
workflows:
main:
jobs:
- pre_deps_golang
- test_go:
requires:
- pre_deps_golang
- build_cli:
requires:
- pre_deps_golang
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
secret/
bin/
*.so
*.h
5 changes: 5 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
goprintenv is maintained by Spatial Current, Inc.

Authors:

* Patrick Dufour (pjdufour)
19 changes: 19 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Contributing to goprintenv

## Contributor License Agreement

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).

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.

## Versioning

This program is released using semantic versioning.

- New flags that alter default behavior are major releases.
- New flags that maintain the same default behavior are minor releases.
- Upgrades of dependencies that don't alert default behavior are patch releases.

## Authors

See [AUTHORS](https://github.com/spatialcurrent/goprintenv/blob/master/AUTHORS) for a list of contributors.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Spatial Current, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
101 changes: 101 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# =================================================================
#
# Copyright (C) 2019 Spatial Current, Inc. - All Rights Reserved
# Released as open source under the MIT License. See LICENSE file.
#
# =================================================================

ifdef GOPATH
GCFLAGS=-trimpath=$(shell printenv GOPATH)/src
else
GCFLAGS=-trimpath=$(shell go env GOPATH)/src
endif

LDFLAGS=-X main.gitBranch=$(shell git branch | grep \* | cut -d ' ' -f2) -X main.gitCommit=$(shell git rev-list -1 HEAD)

.PHONY: help
help: ## Print the help documentation
@grep -E '^[a-zA-Z0-9_-\]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

#
# Dependencies
#

.PHONY: deps_go
deps_go: ## Install Go dependencies
go get -d -t ./...

.PHONY: deps_go_test
deps_go_test: ## Download Go dependencies for tests
go get golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow # download shadow
go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow # install shadow
go get -u github.com/kisielk/errcheck # download and install errcheck
go get -u github.com/client9/misspell/cmd/misspell # download and install misspell
go get -u github.com/gordonklaus/ineffassign # download and install ineffassign
go get -u honnef.co/go/tools/cmd/staticcheck # download and instal staticcheck
go get -u golang.org/x/tools/cmd/goimports # download and install goimports

.PHONY: deps_arm
deps_arm: ## Install dependencies to cross-compile to ARM
# ARMv7
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
# ARMv8
apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu


#
# Go building, formatting, testing, and installing
#

.PHONY: fmt
fmt: ## Format Go source code
go fmt $$(go list ./... )

.PHONY: imports
imports: ## Update imports in Go source code
# If missing, install goimports with: go get golang.org/x/tools/cmd/goimports
goimports -w $$(find . -iname '*.go')

.PHONY: vet
vet: ## Vet Go source code
go vet $$(go list ./...)

.PHONY: test_go
test_go: ## Run Go tests
bash scripts/test.sh

.PHONY: build
build: build_cli ## Build all artifacts

.PHONY: install
install: ## Install goprintenv on current platform
go install -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" github.com/spatialcurrent/goprintenv

#
# Command Line Programs
#

bin/goprintenv_darwin_amd64: ## Build goprintenv for Darwin / amd64
GOOS=darwin GOARCH=amd64 go build -o bin/goprintenv_darwin_amd64 -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" $$(go list ./...)

bin/goprintenv_linux_amd64: ## Build goprintenv for Linux / amd64
GOOS=linux GOARCH=amd64 go build -o bin/goprintenv_linux_amd64 -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" $$(go list ./...)

bin/goprintenv_windows_amd64.exe: ## Build goprintenv for Windows / amd64
GOOS=windows GOARCH=amd64 go build -o bin/goprintenv_windows_amd64.exe -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" $$(go list ./...)

bin/goprintenv_linux_arm64: ## Build goprintenv for Linux / arm64
GOOS=linux GOARCH=arm64 go build -o bin/goprintenv_linux_arm64 -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" $$(go list ./...)

bin/goprintenv_linux_arm: ## Build goprintenv for Linux / arm
GOOS=linux GOARCH=arm go build -o bin/goprintenv_linux_arm -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" $$(go list ./...)

.PHONY: build_cli
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

## Clean

.PHONY: clean
clean: ## Clean artifacts
rm -fr bin
rm -fr dist
81 changes: 81 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
[![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)

# goprintenv

# Description

**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.

**Platforms**

| GOOS | GOARCH |
| ---- | ------ |
| darwin | amd64 |
| linux | amd64 |
| windows | amd64 |
| linux | arm64 |

# Installation

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.

If you do have go already installed, you can just run using `go run main.go` or install with `make install`

# Usage

See the usage below or the following examples.

```
goprintenv is a super simple utility to print environment variables in a custom format. Supports: csv, bson, go, json, properties, tags, toml, tsv, yaml.
Usage:
goprintenv [-f FORMAT] [flags] [variable]...
Flags:
-f, --format string output format, one of: csv, bson, go, json, properties, tags, toml, tsv, yaml (default "properties")
-h, --help help for goprintenv
-0, --null use a NUL byte to end each line instead of a newline character
-p, --pretty use pretty output format
-r, --reversed if output is sorted, sort in reverse alphabetical order
-s, --sorted sort output
```

# Examples

**All Environment Variables**

```shell
goprintenv -f json
```

**Subset of Environment Variables**

`goprintenv` accepts a list of environment variables.

```shell
goprintenv SHELL PATH
```

**Subset of Environment Variables as Pretty JSON**

`goprintenv` accepts a list of environment variables and a custom format.

```shell
goprintenv -f json -p SHELL PATH
```

# Building

You can build all the released artifacts using `make build` or run the make target for a specific operating system and architecture.

# Testing

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).

# Contributing

[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.

# License

This work is distributed under the **MIT License**. See **LICENSE** file.
Loading

0 comments on commit 3ff3ed8

Please sign in to comment.