adding hack/build* to make life easy and added version command. Getting my feet wet (#69)

This commit is contained in:
dr.max 2019-04-15 15:51:01 -07:00 committed by Knative Prow Robot
parent 871eaadd62
commit 7c4f05aa6b
7 changed files with 91 additions and 4 deletions

1
.gitignore vendored
View File

@ -13,6 +13,7 @@
# kn binary itself, if you want to `go build cmd/kn` in the top dir.
/kn
/kn-*`
# emacs tempfiles
\#*

23
hack/build-binaries.sh Executable file
View File

@ -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*

28
hack/build.sh Executable file
View File

@ -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"

View File

@ -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{})

View File

@ -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) {

View File

@ -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
}

View File

@ -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.