Skip to content

Commit

Permalink
Update makefile and code style fix
Browse files Browse the repository at this point in the history
  • Loading branch information
snovichkov committed Feb 7, 2019
1 parent 9ed0944 commit 1dcd3b0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
23 changes: 21 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.PHONY: all test test-with-coverage test-with-coverage-profile lint lint-format lint-import lint-style clean

# Set the mode for code-coverage
GO_TEST_COVERAGE_MODE ?= count
GO_TEST_COVERAGE_FILE_NAME ?= coverage.out
Expand All @@ -9,14 +7,17 @@ GO_LINT_MIN_CONFIDENCE ?= 0.2

all: test

.PHONY: test
test:
@echo "Run unit tests"
@go test -v ./...

.PHONY: test-with-coverage
test-with-coverage:
@echo "Run unit tests with coverage"
@go test -cover ./...

.PHONY: test-with-coverage-profile
test-with-coverage-profile:
@echo "Run unit tests with coverage profile"
@echo "mode: ${GO_TEST_COVERAGE_MODE}" > "${GO_TEST_COVERAGE_FILE_NAME}"
Expand All @@ -25,20 +26,38 @@ test-with-coverage-profile:
@go tool cover -func="${GO_TEST_COVERAGE_FILE_NAME}";
@rm "${GO_TEST_COVERAGE_FILE_NAME}";

.PHONY: fix
fix: fix-format fix-import

.PHONY: fix-import
fix-import:
@echo "Fix imports"
@errors=$$(goimports -l -w -local $(GO_PKG) $$(go list -f "{{ .Dir }}" ./...)); if [ "$${errors}" != "" ]; then echo "$${errors}"; fi

.PHONY: fix-format
fix-format:
@echo "Fix formatting"
@gofmt -w ${GO_FMT_FLAGS} $$(go list -f "{{ .Dir }}" ./...); if [ "$${errors}" != "" ]; then echo "$${errors}"; fi

.PHONY: lint
lint: lint-format lint-import lint-style

.PHONY: lint-format
lint-format:
@echo "Check formatting"
@errors=$$(gofmt -l $$(go list -f "{{ .Dir }}" ./...)); if [ "$${errors}" != "" ]; then echo "Invalid format:\n$${errors}"; exit 1; fi

.PHONY: lint-import
lint-import:
@echo "Check imports"
@errors=$$(goimports -l $$(go list -f "{{ .Dir }}" ./...)); if [ "$${errors}" != "" ]; then echo "Invalid imports:\n$${errors}"; exit 1; fi

.PHONY: lint-style
lint-style:
@echo "Check code style"
@errors=$$(golint -min_confidence=${GO_LINT_MIN_CONFIDENCE} $$(go list ./...)); if [ "$${errors}" != "" ]; then echo "Invalid code style:\n$${errors}"; exit 1; fi

.PHONY: clean
clean:
@echo "Cleanup"
@find . -type f -name "*coverage*.out" -delete
34 changes: 17 additions & 17 deletions glue.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,32 +197,32 @@ func (k *app) initContainer() error {
Use: fmt.Sprintf("%s [command]", os.Args[0]), // TODO: replace to binary name
SilenceUsage: true,
SilenceErrors: true,
PreRun: func(cmd *cobra.Command, args []string) {
PersistentPreRun: func(cmd *cobra.Command, args []string) {
registry.Set("cli.cmd", cmd)
registry.Set("cli.args", args)
},
}

// register commands by tag
for name, def := range ctn.Definitions() {
Tags:
Tags:
for _, tag := range def.Tags {
switch tag.Name {
case TagCliCommand:
var command *cobra.Command
if err = ctn.Fill(name, &command); err != nil {
return nil, err
}

rootCmd.AddCommand(command)
break Tags
case TagRootPersistentFlags:
var pf *pflag.FlagSet
if err = ctn.Fill(name, &pf); err != nil {
return nil, err
}
rootCmd.PersistentFlags().AddFlagSet(pf)
break Tags
case TagCliCommand:
var command *cobra.Command
if err = ctn.Fill(name, &command); err != nil {
return nil, err
}

rootCmd.AddCommand(command)
break Tags
case TagRootPersistentFlags:
var pf *pflag.FlagSet
if err = ctn.Fill(name, &pf); err != nil {
return nil, err
}
rootCmd.PersistentFlags().AddFlagSet(pf)
break Tags
}
}
}
Expand Down

0 comments on commit 1dcd3b0

Please sign in to comment.