Skip to content

Commit

Permalink
Added liqoctl version command
Browse files Browse the repository at this point in the history
  • Loading branch information
GabriFila committed Sep 11, 2021
1 parent bd1a7cf commit 9c9d51d
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 2 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,10 @@ jobs:
persist-credentials: false

- name: Build Liqoctl
run: go build -o liqoctl-${{ matrix.goos }}-${{ matrix.goarch }} -ldflags="-s -w" ./cmd/liqoctl
run: >
go build -o liqoctl-${{ matrix.goos }}-${{ matrix.goarch }}
-ldflags="-s -w -X 'github.com/liqotech/liqo/pkg/liqoctl/version.liqoctlVersion=${{ needs.configure.outputs.commit-ref }}'"
./cmd/liqoctl
env:
CGO_ENABLED: 0
GOOS: ${{ matrix.goos }}
Expand Down Expand Up @@ -308,4 +311,4 @@ jobs:
token: ${{ secrets.CI_TOKEN }}
tag: ${{ needs.configure.outputs.commit-ref }}
name: ${{ needs.configure.outputs.commit-ref }}
prerelease: ${{ steps.semver_parser.outputs.prerelease != '' }}
prerelease: ${{ steps.semver_parser.outputs.prerelease != '' }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ externalcrds

# directory where liqo stores the bearer tokens got by identity providers (i.e. Amazon IAM)
token

# to ease the local development of liqoctl
/liqoctl
1 change: 1 addition & 0 deletions cmd/liqoctl/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ func NewRootCommand(ctx context.Context) *cobra.Command {
rootCmd.AddCommand(newAddCommand(ctx))
rootCmd.AddCommand(newGenerateAddCommand(ctx))
rootCmd.AddCommand(newDocsCommand(ctx))
rootCmd.AddCommand(newVersionCommand())
return rootCmd
}
34 changes: 34 additions & 0 deletions cmd/liqoctl/cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2019-2021 The Liqo 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 cmd

import (
"github.com/spf13/cobra"

"github.com/liqotech/liqo/pkg/liqoctl/version"
)

// installCmd represents the generateInstall command.
func newVersionCommand() *cobra.Command {
var verCmd = &cobra.Command{
Use: version.LiqoctlVersionCommand,
Short: version.LiqoctlVersionShortHelp,
Long: version.LiqoctlVersionLongHelp,
Run: func(cmd *cobra.Command, args []string) {
version.HandleVersionCommand()
},
}
return verCmd
}
24 changes: 24 additions & 0 deletions pkg/liqoctl/version/consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2019-2021 The Liqo 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 version

// LiqoctlVersionShortHelp contains the short help message for the version Liqoctl command.
const LiqoctlVersionShortHelp = "Print current liqoctl client version"

// LiqoctlVersionLongHelp contains the short help message for the version Liqoctl command.
const LiqoctlVersionLongHelp = "Print current liqoctl client version"

// LiqoctlVersionCommand contains the use command for the version Liqoctl command.
const LiqoctlVersionCommand = "version"
16 changes: 16 additions & 0 deletions pkg/liqoctl/version/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2019-2021 The Liqo 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 version contains the logic that handle the version command in liqoctl
package version
32 changes: 32 additions & 0 deletions pkg/liqoctl/version/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2019-2021 The Liqo 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 version

import (
"fmt"
)

// if you need to rename the following variables, change also the build command for liqoctl.
var liqoctlVersion = "development"
var liqoctlSHA = ""

// HandleVersionCommand outputs the liqoctl add command to use to add the target cluster.
func HandleVersionCommand() {
fmt.Println()
fmt.Printf("Current Liqoctl client version: %s\n\n", liqoctlVersion)
if liqoctlSHA != "" {
fmt.Printf("Current Liqoctl client commit SHA: %s\n\n", liqoctlSHA)
}
}

0 comments on commit 9c9d51d

Please sign in to comment.