From 2ea6908ee8ba688ba0cd2203183200d1222bb23d Mon Sep 17 00:00:00 2001 From: licaonfee Date: Sat, 17 Oct 2020 15:48:52 -0300 Subject: [PATCH] feat: add example --- .github/dependabot.yml | 11 +++++++++++ .github/workflows/go.yml | 20 ++++++++++++++++++++ Makefile | 19 +++++++++++++++++++ README.md | 32 +++++++++++++++++++++++++++++++- 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/go.yml create mode 100644 Makefile diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..eb4bfe6 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "gomod" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "daily" diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..663a5be --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,20 @@ +on: [ "push", "pull_request" ] +name: Run test +jobs: + checks: + name: run + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: run + uses: cedrickring/golang-action@1.5.2 + - name: Convert coverage to lcov + uses: jandelgado/gcov2lcov-action@v1.0.2 + with: + infile: coverage.out + outfile: coverage.lcov + - name: Coveralls GitHub Action + uses: coverallsapp/github-action@v1.1.0 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + path-to-lcov: coverage.lcov diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8a43686 --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +# Go parameters +GOCMD=go +GOBUILD=$(GOCMD) build +GOTEST=$(GOCMD) test +GOTOOL=$(GOCMD) tool + +all: deps utest cover + +deps: + $(GOCMD) mod download + +utest: + $(GOTEST) -race -count 1 -timeout 30s -coverprofile coverage.out ./... +cover: utest + $(GOTOOL) cover -func=coverage.out + +clean: + rm -f ./coverage.out + diff --git a/README.md b/README.md index a82b12b..e8ba5fe 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,32 @@ # envy -Asbtract Environment variables + +Environment variables utilities + +## Usage + +```go +package main + +import ( + "flag" + "fmt" + "github.com/licaonfee/envy" + "os" +) + +func main() { + //this value should be ignored, because -my-flag is set + os.Setenv("MY_FLAG", "fooo") + //this value is passed to my-time + os.Setenv("MY_TIME", "1m") + os.Args = []string{"my-bin", "-my-flag", "bar"} + f := flag.String("my-flag", "", "my flag") + x := flag.Duration("my-time", 0, "my-time") + flag.Parse() + + envy.FillFlags(flag.CommandLine) + fmt.Printf("my-flag: %s \n", *f) + fmt.Printf("my-time: %v \n", *x) +} +``` +