diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index fa8e2ade8..eb77257b7 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -73,7 +73,7 @@ You can link that script into a directory within your search `$PATH`. This allow * `build.sh` - Compile, test, generate docs and format source code * `build.sh -f` - Compile only * `build.sh -f -t` - Compile & test -* `build.sh -u` - Update dependencies before compiling +* `build.sh -c` - Update dependencies, regenerate documentation and format source files * `build.sh -w` - Enter watch mode for automatic recompilation * `build.sh -w -t` - Enter watch mode for automatic recompilation & running tests diff --git a/docs/cmd/kn.md b/docs/cmd/kn.md index 08b540755..af684aa3c 100644 --- a/docs/cmd/kn.md +++ b/docs/cmd/kn.md @@ -19,7 +19,6 @@ Manage your Knative building blocks: ### SEE ALSO -* [kn completion](kn_completion.md) - Output shell completion code (default Bash) * [kn revision](kn_revision.md) - Revision command group * [kn route](kn_route.md) - Route command group * [kn service](kn_service.md) - Service command group diff --git a/docs/cmd/kn_completion.md b/docs/cmd/kn_completion.md deleted file mode 100644 index 356364bb0..000000000 --- a/docs/cmd/kn_completion.md +++ /dev/null @@ -1,30 +0,0 @@ -## kn completion - -Output shell completion code (default Bash) - -### Synopsis - -Output shell completion code (default Bash) - -``` -kn completion [flags] -``` - -### Options - -``` - -h, --help help for completion - --zsh Generates completion code for Zsh shell. -``` - -### Options inherited from parent commands - -``` - --config string config file (default is $HOME/.kn/config.yaml) - --kubeconfig string kubectl config file (default is $HOME/.kube/config) -``` - -### SEE ALSO - -* [kn](kn.md) - Knative client - diff --git a/go.sum b/go.sum index 330faf3a7..29a03df64 100644 --- a/go.sum +++ b/go.sum @@ -342,6 +342,7 @@ golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZe golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20181011042414-1f849cf54d09 h1:6Cq5LXQ/D2J5E7sYJemWSQApczOzY1rxSp8TWloyxIY= golang.org/x/tools v0.0.0-20181011042414-1f849cf54d09/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= diff --git a/hack/build.sh b/hack/build.sh index ebf5ccc3a..cb3f611d2 100755 --- a/hack/build.sh +++ b/hack/build.sh @@ -47,16 +47,17 @@ run() { fi if $(has_flag --watch -w); then + # Build and test first + go_build + go_test + + # Go in endless loop, to be stopped with CTRL-C watch - # No exit, needs to be stopped with CTRL-C anyways fi - if $(has_flag -u --update); then + if ! $(has_flag --fast -f) || $(has_flag --codegen -c); then # Update dependencies update_deps - fi - - if ! $(has_flag --fast -f); then # Format source code and cleanup imports source_format @@ -69,6 +70,11 @@ run() { generate_docs fi + # Stop when only codegen is requested + if $(has_flag --codegen -c); then + exit 0 + fi + # Run build go_build @@ -91,7 +97,7 @@ source_format() { which goimports >/dev/null 2>&1 if [ $? -ne 0 ]; then echo "โœ‹ No 'goimports' found. Please use" - echo "โœ‹ go get golang.org/x/tools/cmd/goimports" + echo "โœ‹ go install golang.org/x/tools/cmd/goimports" echo "โœ‹ to enable import cleanup. Import cleanup skipped." # Run go fmt instead @@ -112,8 +118,14 @@ go_build() { go_test() { local test_output=$(mktemp /tmp/kn-client-test-output.XXXXXX) - local red="" - local reset="" + + local red="" + local reset="" + # Use color only when a terminal is set + if [ -t 1 ]; then + red="" + reset="" + fi echo "๐Ÿงช ${S}Test" set +e @@ -240,10 +252,9 @@ Usage: $(basename $BASH_SOURCE) [... options ...] with the following options: --f --fast Only compile (without formatting, testing, doc generation) +-f --fast Only compile (without dep update, formatting, testing, doc gen) -t --test Run tests when used with --fast or --watch --i --imports Organize and cleanup imports --u --update Update dependencies before compiling +-c --codegen Runs formatting, doc gen and update without compiling/testing -w --watch Watch for source changes and recompile in fast mode -h --help Display this help message --verbose More output diff --git a/hack/update-deps.sh b/hack/update-deps.sh deleted file mode 100755 index 1e8e98030..000000000 --- a/hack/update-deps.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2019 The Knative Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -o errexit -set -o nounset -set -o pipefail - -# GO111MODULE used so that it works no matter if someone has this repo -# cloned under $GOPATH or not -GO111MODULE=on go mod vendor diff --git a/hack/verify-codegen.sh b/hack/verify-codegen.sh index 158ea3621..4e2c93805 100755 --- a/hack/verify-codegen.sh +++ b/hack/verify-codegen.sh @@ -20,33 +20,17 @@ set -o pipefail source $(dirname $0)/../vendor/github.com/knative/test-infra/scripts/library.sh -readonly TMP_DIFFROOT="$(mktemp -d ${REPO_ROOT_DIR}/tmpdiffroot.XXXXXX)" +# Needed later +go install golang.org/x/tools/cmd/goimports -cleanup() { - rm -rf "${TMP_DIFFROOT}" -} - -trap "cleanup" EXIT SIGINT - -cleanup - -# Save working tree state -mkdir -p "${TMP_DIFFROOT}/vendor" -cp -aR "${REPO_ROOT_DIR}/go.sum" "${REPO_ROOT_DIR}/vendor" "${TMP_DIFFROOT}" - -"${REPO_ROOT_DIR}/hack/update-deps.sh" -echo "Diffing ${REPO_ROOT_DIR} against freshly update dependencies" -ret=0 -diff -Naupr --no-dereference "${REPO_ROOT_DIR}/vendor" "${TMP_DIFFROOT}/vendor" || ret=1 - -# Restore working tree state -rm -fr "${REPO_ROOT_DIR}/go.sum" "${REPO_ROOT_DIR}/vendor" -cp -aR "${TMP_DIFFROOT}"/* "${REPO_ROOT_DIR}" - -if [[ $ret -eq 0 ]] -then - echo "${REPO_ROOT_DIR} up to date." +"${REPO_ROOT_DIR}"/hack/build.sh --codegen +if output="$(git status --porcelain)" && [ -z "$output" ]; then + echo "${REPO_ROOT_DIR} is up to date." else - echo "ERROR: ${REPO_ROOT_DIR} is out of date. Please run ./hack/update-deps.sh" + echo "ERROR: Modified files found:" + git status --porcelain + echo "ERROR: Diff" + git diff + echo "ERROR: ${REPO_ROOT_DIR} is out of date. Please run ./hack/build.sh -u and commit." exit 1 fi diff --git a/pkg/kn/commands/completion.go b/pkg/kn/commands/completion.go index 5ea127891..365a5814e 100644 --- a/pkg/kn/commands/completion.go +++ b/pkg/kn/commands/completion.go @@ -28,9 +28,9 @@ func NewCompletionCommand(p *KnParams) *cobra.Command { var completionFlags CompletionFlags completionCmd := &cobra.Command{ - Use: "completion", - Short: "Output shell completion code (default Bash)", - Hidden: true, // Don't show this in help listing. + Use: "completion", + Short: "Output shell completion code (default Bash)", + Hidden: true, // Don't show this in help listing. Run: func(cmd *cobra.Command, args []string) { if completionFlags.Zsh { cmd.Root().GenZshCompletion(os.Stdout)