Skip to content

Commit

Permalink
Merge branch 'master' into improve-help
Browse files Browse the repository at this point in the history
  • Loading branch information
mumoshu authored Dec 6, 2018
2 parents eb00133 + a73f05f commit c4b764e
Show file tree
Hide file tree
Showing 14 changed files with 188 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ builds:
- CGO_ENABLED=0
ldflags:
# gitTag set from a generated file (see ./tag_release.sh)
- -s -w -X main.builtAt={{.Date}} -X main.gitCommit={{.Commit}}
- -s -w -X github.com/weaveworks/eksctl/pkg/version.builtAt={{.Date}} -X github.com/weaveworks/eksctl/pkg/version.gitCommit={{.Commit}}
goos:
- windows
- darwin
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
built_at := $(shell date +%s)
git_commit := $(shell git describe --dirty --always)

version_pkg := github.com/weaveworks/eksctl/pkg/version

EKSCTL_BUILD_IMAGE ?= weaveworks/eksctl:build
EKSCTL_IMAGE ?= weaveworks/eksctl:latest

Expand All @@ -20,7 +22,7 @@ install-build-deps: ## Install dependencies (packages and tools)

.PHONY: build
build: ## Build eksctl
@go build -ldflags "-X main.gitCommit=$(git_commit) -X main.builtAt=$(built_at)" ./cmd/eksctl
@go build -ldflags "-X $(version_pkg).gitCommit=$(git_commit) -X $(version_pkg).builtAt=$(built_at)" ./cmd/eksctl

##@ Testing & CI

Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,31 @@ eksctl apply --cluster-config advanced-cluster.yaml
```
-->

### Shell Completion

To enable bash completion, run the following, or put it in `~/.bashrc` or `~/.profile`:
```
. <(eksctl completion bash)
```

Or for zsh, run:
```
mkdir -p ~/.zsh/completion/
eksctl completion zsh > ~/.zsh/completion/_eksctl
```
and put the following in `~/.zshrc`:
```
fpath=($fpath ~/.zsh/completion)
```
Note if you're not running a distribution like oh-my-zsh you may first have to enable autocompletion:
```
autoload -U compinit
compinit
```

To make the above persistent, run the first two lines, and put the


## Project Roadmap

### Developer use-case (0.2.0)
Expand Down
2 changes: 2 additions & 0 deletions cmd/eksctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/kubicorn/kubicorn/pkg/logger"
"github.com/spf13/cobra"
"github.com/weaveworks/eksctl/pkg/ctl/completion"
"github.com/weaveworks/eksctl/pkg/ctl/create"
"github.com/weaveworks/eksctl/pkg/ctl/delete"
"github.com/weaveworks/eksctl/pkg/ctl/get"
Expand Down Expand Up @@ -45,4 +46,5 @@ func addCommands() {
rootCmd.AddCommand(get.Command())
rootCmd.AddCommand(scale.Command())
rootCmd.AddCommand(utils.Command())
rootCmd.AddCommand(completion.Command(rootCmd))
}
14 changes: 3 additions & 11 deletions cmd/eksctl/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,18 @@ package main
import (
"github.com/spf13/cobra"

"github.com/weaveworks/eksctl/pkg/version"

"github.com/kubicorn/kubicorn/pkg/logger"
)

//go:generate go run version_generate.go

func versionCmd() *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "Output the version of eksctl",
Run: func(_ *cobra.Command, _ []string) {
versionInfo := map[string]string{
"builtAt": builtAt,
"gitCommit": gitCommit,
}

if gitTag != "" {
versionInfo["gitTag"] = gitTag
}

logger.Info("versionInfo = %#v", versionInfo)
logger.Info("%#v", version.Get())
},
}
}
32 changes: 0 additions & 32 deletions cmd/eksctl/version_generate.go

This file was deleted.

9 changes: 0 additions & 9 deletions cmd/eksctl/version_norelease.go

This file was deleted.

7 changes: 0 additions & 7 deletions cmd/eksctl/version_release.go

This file was deleted.

61 changes: 61 additions & 0 deletions pkg/ctl/completion/completion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package completion

import (
"os"

"github.com/kubicorn/kubicorn/pkg/logger"

"github.com/spf13/cobra"
)

// Command will create the `completion` commands
func Command(rootCmd *cobra.Command) *cobra.Command {
var bashCompletionCmd = &cobra.Command{
Use: "bash",
Short: "Generates bash completion scripts",
Long: `To load completion run
. <(eksctl completion bash)
To configure your bash shell to load completions for each session add to your bashrc
# ~/.bashrc or ~/.profile
. <(eksctl completion bash)
`,
Run: func(cmd *cobra.Command, args []string) {
rootCmd.GenBashCompletion(os.Stdout)
},
}
var zshCompletionCmd = &cobra.Command{
Use: "zsh",
Short: "Generates zsh completion scripts",
Long: `To configure your zsh shell, run:
mkdir -p ~/.zsh/completion/
eksctl completion zsh > ~/.zsh/completion/_eksctl
and put the following in ~/.zshrc:
fpath=($fpath ~/.zsh/completion)
`,
Run: func(cmd *cobra.Command, args []string) {
rootCmd.GenZshCompletion(os.Stdout)
},
}

cmd := &cobra.Command{
Use: "completion",
Short: "Generates shell completion scripts",
Run: func(c *cobra.Command, _ []string) {
if err := c.Help(); err != nil {
logger.Debug("ignoring error %q", err.Error())
}
},
}

cmd.AddCommand(bashCompletionCmd)
cmd.AddCommand(zshCompletionCmd)

return cmd
}
8 changes: 8 additions & 0 deletions pkg/eks/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/weaveworks/eksctl/pkg/ami"
"github.com/weaveworks/eksctl/pkg/cfn/manager"
"github.com/weaveworks/eksctl/pkg/eks/api"
"github.com/weaveworks/eksctl/pkg/version"

"github.com/weaveworks/eksctl/pkg/az"

Expand All @@ -16,6 +17,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudformation"
"github.com/aws/aws-sdk-go/service/cloudformation/cloudformationiface"
Expand Down Expand Up @@ -262,6 +264,12 @@ func (c *ClusterProvider) newSession(spec *api.ProviderConfig, endpoint string,

s := session.Must(session.NewSessionWithOptions(opts))

s.Handlers.Build.PushFrontNamed(request.NamedHandler{
Name: "eksctlUserAgent",
Fn: request.MakeAddToUserAgentHandler(
"eksctl", version.String()),
})

if spec.Region == "" {
if *s.Config.Region != "" {
// set cluster config region, based on session config
Expand Down
7 changes: 7 additions & 0 deletions pkg/version/norelease.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// +build !release

package version

var (
builtAt, gitCommit, gitTag string
)
10 changes: 10 additions & 0 deletions pkg/version/release.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// +build release

package version

// This file was generated by release_generate.go; DO NOT EDIT.

// Values of builtAt and gitCommit will be set by the linker.
var builtAt = ""
var gitCommit = ""
var gitTag = "0.1.11"
37 changes: 37 additions & 0 deletions pkg/version/release_generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// +build ignore

package main

import (
"bytes"
"io/ioutil"
"log"
"os"

. "github.com/dave/jennifer/jen"
)

func main() {
f := NewFile("version")

f.Comment("This file was generated by release_generate.go; DO NOT EDIT.")
f.Line()

f.Comment("Values of builtAt and gitCommit will be set by the linker.")
f.Var().Id("builtAt").Op("=").Lit("")
f.Var().Id("gitCommit").Op("=").Lit("")

gitTag := os.Getenv("RELEASE_GIT_TAG")
f.Var().Id("gitTag").Op("=").Lit(gitTag)

buf := &bytes.Buffer{}
if _, err := buf.WriteString("// +build release\n\n"); err != nil {
log.Fatal(err.Error())
}
if err := f.Render(buf); err != nil {
log.Fatal(err.Error())
}
if err := ioutil.WriteFile("release.go", buf.Bytes(), 0644); err != nil {
log.Fatal(err.Error())
}
}
31 changes: 31 additions & 0 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package version

import (
"encoding/json"
)

//go:generate go run ./release_generate.go

// Info hold version information
type Info struct {
BuiltAt string
GitCommit string `json:",omitempty"`
GitTag string `json:",omitempty"`
}

var info = Info{
BuiltAt: builtAt,
GitCommit: gitCommit,
GitTag: gitTag,
}

// Get return version Info struct
func Get() Info { return info }

// String return version info as JSON
func String() string {
if data, err := json.Marshal(info); err == nil {
return string(data)
}
return ""
}

0 comments on commit c4b764e

Please sign in to comment.