diff --git a/.gitignore b/.gitignore index 29b8e342d..ceb30d066 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ # kn binary itself, if you want to `go build cmd/kn` in the top dir. /kn +/kn-*` # emacs tempfiles \#* diff --git a/hack/build-binaries.sh b/hack/build-binaries.sh new file mode 100755 index 000000000..d28e009cf --- /dev/null +++ b/hack/build-binaries.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Copyright 2018 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 -e -x -u + +GOOS=darwin GOARCH=amd64 go build -o kn-darwin-amd64 ./cmd/... +GOOS=linux GOARCH=amd64 go build -o kn-linux-amd64 ./cmd/... +GOOS=windows GOARCH=amd64 go build -o kn-windows-amd64.exe ./cmd/... + +shasum -a 256 ./kn-*-amd64* diff --git a/hack/build.sh b/hack/build.sh new file mode 100755 index 000000000..c5997e80e --- /dev/null +++ b/hack/build.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# Copyright 2018 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 -e -x -u + +VERSION=0.0.0 +BUILDTIME=`date -u +%Y%m%d.%H%M%S` + +go fmt ./cmd/... ./pkg/... + +go build -ldflags "-X github.com/knative/client/pkg/kn/commands.Version=$VERSION.$BUILDTIME" ./cmd/... + +./kn version + +echo "Success" diff --git a/pkg/kn/commands/root.go b/pkg/kn/commands/root.go index 08f9411df..28776136e 100644 --- a/pkg/kn/commands/root.go +++ b/pkg/kn/commands/root.go @@ -77,6 +77,7 @@ Eventing: Manage event subscriptions and channels. Connect up event sources.`, rootCmd.AddCommand(NewServiceCommand(p)) rootCmd.AddCommand(NewRevisionCommand(p)) rootCmd.AddCommand(NewCompletionCommand(p)) + rootCmd.AddCommand(NewVersionCommand(p)) // For glog parse error. flag.CommandLine.Parse([]string{}) diff --git a/pkg/kn/commands/service_describe_test.go b/pkg/kn/commands/service_describe_test.go index 0d5f8ff5c..4cac4a46c 100644 --- a/pkg/kn/commands/service_describe_test.go +++ b/pkg/kn/commands/service_describe_test.go @@ -16,17 +16,17 @@ package commands import ( "bytes" - "testing" "encoding/json" + "testing" - "sigs.k8s.io/yaml" - "k8s.io/apimachinery/pkg/api/equality" "github.com/knative/serving/pkg/apis/serving/v1alpha1" serving "github.com/knative/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1" "github.com/knative/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1/fake" + "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" client_testing "k8s.io/client-go/testing" + "sigs.k8s.io/yaml" ) func fakeServiceDescribe(args []string, response *v1alpha1.Service) (action client_testing.Action, output string, err error) { diff --git a/pkg/kn/commands/version.go b/pkg/kn/commands/version.go new file mode 100644 index 000000000..12a445e07 --- /dev/null +++ b/pkg/kn/commands/version.go @@ -0,0 +1,34 @@ +// 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. + +package commands + +import ( + "fmt" + "github.com/spf13/cobra" +) + +var Version string + +func NewVersionCommand(p *KnParams) *cobra.Command { + versionCmd := &cobra.Command{ + Use: "version", + Short: "Prints the client version", + RunE: func(cmd *cobra.Command, args []string) error { + fmt.Println(fmt.Sprintf("Client Version: %s\n", Version)) + return nil + }, + } + return versionCmd +} diff --git a/pkg/serving/config_changes_test.go b/pkg/serving/config_changes_test.go index ba416acaf..6622d339a 100644 --- a/pkg/serving/config_changes_test.go +++ b/pkg/serving/config_changes_test.go @@ -1,4 +1,4 @@ -// Copyright ¬© 2019 The Knative Authors +// 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.