cli: Add license flag
This patch adds the option to print the license with a cli flag. It uses go-bindata to store the license file. The file is generated by running `make bindata` and the result is stored in the bindata directory.
This commit is contained in:
committed by
James Shubin
parent
406aa55667
commit
62ca12608d
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,6 +6,7 @@
|
|||||||
old/
|
old/
|
||||||
tmp/
|
tmp/
|
||||||
*_stringer.go
|
*_stringer.go
|
||||||
|
bindata/*.go
|
||||||
mgmt
|
mgmt
|
||||||
mgmt.static
|
mgmt.static
|
||||||
mgmt.iml
|
mgmt.iml
|
||||||
|
|||||||
12
Makefile
12
Makefile
@@ -16,8 +16,8 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
SHELL = /usr/bin/env bash
|
SHELL = /usr/bin/env bash
|
||||||
.PHONY: all art cleanart version program path deps run race generate build clean test gofmt yamlfmt format docs rpmbuild mkdirs rpm srpm spec tar upload upload-sources upload-srpms upload-rpms copr
|
.PHONY: all art cleanart version program path deps run race bindata generate build clean test gofmt yamlfmt format docs rpmbuild mkdirs rpm srpm spec tar upload upload-sources upload-srpms upload-rpms copr
|
||||||
.SILENT: clean
|
.SILENT: clean bindata
|
||||||
|
|
||||||
GO_FILES := $(shell find . -name '*.go')
|
GO_FILES := $(shell find . -name '*.go')
|
||||||
SVERSION := $(or $(SVERSION),$(shell git describe --match '[0-9]*\.[0-9]*\.[0-9]*' --tags --dirty --always))
|
SVERSION := $(or $(SVERSION),$(shell git describe --match '[0-9]*\.[0-9]*\.[0-9]*' --tags --dirty --always))
|
||||||
@@ -101,10 +101,14 @@ run:
|
|||||||
race:
|
race:
|
||||||
find . -maxdepth 1 -type f -name '*.go' -not -name '*_test.go' | xargs go run -race -ldflags "-X main.program=$(PROGRAM) -X main.version=$(SVERSION)"
|
find . -maxdepth 1 -type f -name '*.go' -not -name '*_test.go' | xargs go run -race -ldflags "-X main.program=$(PROGRAM) -X main.version=$(SVERSION)"
|
||||||
|
|
||||||
|
# generate go files from non-go source
|
||||||
|
bindata:
|
||||||
|
$(MAKE) --quiet -C bindata
|
||||||
|
|
||||||
generate:
|
generate:
|
||||||
go generate
|
go generate
|
||||||
|
|
||||||
build: $(PROGRAM)
|
build: bindata $(PROGRAM)
|
||||||
|
|
||||||
$(PROGRAM): $(GO_FILES)
|
$(PROGRAM): $(GO_FILES)
|
||||||
@echo "Building: $(PROGRAM), version: $(SVERSION)..."
|
@echo "Building: $(PROGRAM), version: $(SVERSION)..."
|
||||||
@@ -120,7 +124,7 @@ clean:
|
|||||||
rm -f *_stringer.go # generated by `go generate`
|
rm -f *_stringer.go # generated by `go generate`
|
||||||
rm -f *_mock.go # generated by `go generate`
|
rm -f *_mock.go # generated by `go generate`
|
||||||
|
|
||||||
test:
|
test: bindata
|
||||||
./test.sh
|
./test.sh
|
||||||
|
|
||||||
gofmt:
|
gofmt:
|
||||||
|
|||||||
33
bindata/Makefile
Normal file
33
bindata/Makefile
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
# Mgmt
|
||||||
|
# Copyright (C) 2013-2017+ James Shubin and the project contributors
|
||||||
|
# Written by James Shubin <james@shubin.ca> and the project contributors
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# The bindata target generates go files from any source defined below. To use
|
||||||
|
# the files, import the "bindata" package and use:
|
||||||
|
# `bytes, err := bindata.Asset("FILEPATH")`
|
||||||
|
# where FILEPATH is the path of the original input file relative to `bindata/`.
|
||||||
|
|
||||||
|
.PHONY: build
|
||||||
|
default: build
|
||||||
|
|
||||||
|
build: bindata.go
|
||||||
|
|
||||||
|
# add more input files as dependencies at the end here...
|
||||||
|
bindata.go: ../COPYING
|
||||||
|
# go-bindata --pkg bindata -o {OUTPUT} {INPUT}
|
||||||
|
go-bindata --pkg bindata -o ./$@ $^
|
||||||
|
# gofmt the output file
|
||||||
|
gofmt -s -w $@
|
||||||
28
lib/cli.go
28
lib/cli.go
@@ -24,6 +24,7 @@ import (
|
|||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/purpleidea/mgmt/bindata"
|
||||||
"github.com/purpleidea/mgmt/hcl"
|
"github.com/purpleidea/mgmt/hcl"
|
||||||
"github.com/purpleidea/mgmt/puppet"
|
"github.com/purpleidea/mgmt/puppet"
|
||||||
"github.com/purpleidea/mgmt/yamlgraph"
|
"github.com/purpleidea/mgmt/yamlgraph"
|
||||||
@@ -188,7 +189,32 @@ func CLI(program, version string, flags Flags) error {
|
|||||||
app.Metadata = map[string]interface{}{ // additional flags
|
app.Metadata = map[string]interface{}{ // additional flags
|
||||||
"flags": flags,
|
"flags": flags,
|
||||||
}
|
}
|
||||||
//app.Action = ... // without a default action, help runs
|
|
||||||
|
// if no app.Command is specified
|
||||||
|
app.Action = func(c *cli.Context) error {
|
||||||
|
// print the license
|
||||||
|
if c.Bool("license") {
|
||||||
|
license, err := bindata.Asset("../COPYING") // use go-bindata to get the bytes
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("%s", license)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// print help if no flags are set
|
||||||
|
cli.ShowAppHelp(c)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// global flags
|
||||||
|
app.Flags = []cli.Flag{
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "license",
|
||||||
|
Usage: "prints the software license",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
app.Commands = []cli.Command{
|
app.Commands = []cli.Command{
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -78,7 +78,8 @@ ret=$?
|
|||||||
if [[ $ret != 0 ]]; then
|
if [[ $ret != 0 ]]; then
|
||||||
go get golang.org/x/tools/cmd/vet # add in `go vet` for travis
|
go get golang.org/x/tools/cmd/vet # add in `go vet` for travis
|
||||||
fi
|
fi
|
||||||
go get golang.org/x/tools/cmd/stringer # for automatic stringer-ing
|
go get golang.org/x/tools/cmd/stringer # for automatic stringer-ing
|
||||||
go get github.com/golang/lint/golint # for `golint`-ing
|
go get github.com/jteeuwen/go-bindata/go-bindata # for compiling in non golang files
|
||||||
|
go get github.com/golang/lint/golint # for `golint`-ing
|
||||||
go get -u gopkg.in/alecthomas/gometalinter.v1 && mv "$(dirname $(which gometalinter.v1))/gometalinter.v1" "$(dirname $(which gometalinter.v1))/gometalinter" && gometalinter --install # bonus
|
go get -u gopkg.in/alecthomas/gometalinter.v1 && mv "$(dirname $(which gometalinter.v1))/gometalinter.v1" "$(dirname $(which gometalinter.v1))/gometalinter" && gometalinter --install # bonus
|
||||||
cd "$XPWD" >/dev/null
|
cd "$XPWD" >/dev/null
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ if [ "$COMMITS" != "" ] && [ "$COMMITS" -gt "1" ]; then
|
|||||||
HACK="yes"
|
HACK="yes"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
LINT=`find . -maxdepth 3 -iname '*.go' -not -path './old/*' -not -path './tmp/*' -exec golint {} \;` # current golint output
|
LINT=`find . -maxdepth 3 -iname '*.go' -not -path './old/*' -not -path './tmp/*' -not -path './bindata/*' -exec golint {} \;` # current golint output
|
||||||
COUNT=`echo -e "$LINT" | wc -l` # number of golint problems in current branch
|
COUNT=`echo -e "$LINT" | wc -l` # number of golint problems in current branch
|
||||||
[ "$LINT" = "" ] && echo PASS && exit # everything is "perfect"
|
[ "$LINT" = "" ] && echo PASS && exit # everything is "perfect"
|
||||||
echo "$LINT" # display the issues
|
echo "$LINT" # display the issues
|
||||||
@@ -51,7 +51,7 @@ while read -r line; do
|
|||||||
done <<< "$NUMSTAT1" # three < is the secret to putting a variable into read
|
done <<< "$NUMSTAT1" # three < is the secret to putting a variable into read
|
||||||
|
|
||||||
git checkout "$PREVIOUS" &>/dev/null # previous commit
|
git checkout "$PREVIOUS" &>/dev/null # previous commit
|
||||||
LINT1=`find . -maxdepth 3 -iname '*.go' -not -path './old/*' -not -path './tmp/*' -exec golint {} \;`
|
LINT1=`find . -maxdepth 3 -iname '*.go' -not -path './old/*' -not -path './tmp/*' -not -path './bindata/*' -exec golint {} \;`
|
||||||
COUNT1=`echo -e "$LINT1" | wc -l` # number of golint problems in older branch
|
COUNT1=`echo -e "$LINT1" | wc -l` # number of golint problems in older branch
|
||||||
|
|
||||||
# clean up
|
# clean up
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ gometalinter="$gml"
|
|||||||
|
|
||||||
# loop through directories in an attempt to scan each go package
|
# loop through directories in an attempt to scan each go package
|
||||||
# TODO: lint the *.go examples as individual files and not as a single *.go
|
# TODO: lint the *.go examples as individual files and not as a single *.go
|
||||||
for dir in `find . -maxdepth 5 -type d -not -path './old/*' -not -path './old' -not -path './tmp/*' -not -path './tmp' -not -path './.*' -not -path './vendor/*' -not -path './examples/*' -not -path './test/*'`; do
|
for dir in `find . -maxdepth 5 -type d -not -path './old/*' -not -path './old' -not -path './tmp/*' -not -path './tmp' -not -path './.*' -not -path './vendor/*' -not -path './bindata/*'-not -path ' ./examples/*' -not -path './test/*'`; do
|
||||||
match="$dir/*.go"
|
match="$dir/*.go"
|
||||||
#echo "match is: $match"
|
#echo "match is: $match"
|
||||||
if ! ls $match &>/dev/null; then
|
if ! ls $match &>/dev/null; then
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ done < "$FILE"
|
|||||||
cd "${ROOT}"
|
cd "${ROOT}"
|
||||||
|
|
||||||
find_files() {
|
find_files() {
|
||||||
git ls-files | grep '\.go$' | grep -v '^examples/' | grep -v '^test/'
|
git ls-files | grep '\.go$' | grep -v '^bindata/' | grep -v '^examples/' | grep -v '^test/'
|
||||||
}
|
}
|
||||||
|
|
||||||
bad_files=$(
|
bad_files=$(
|
||||||
|
|||||||
Reference in New Issue
Block a user