Skip to content

Commit

Permalink
Review built-in help
Browse files Browse the repository at this point in the history
  • Loading branch information
errordeveloper committed Jun 5, 2018
1 parent 3c28128 commit 57871f4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
16 changes: 11 additions & 5 deletions cmd/eksctl/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import (

func createCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "create",
Use: "create",
Short: "Create resource(s)",
Run: func(c *cobra.Command, _ []string) {
c.Help()
},
Expand All @@ -40,11 +41,16 @@ var (
kubeconfigPath string
)

func getClusterName() string {
return fmt.Sprintf("%s-%d", namer.RandomName(), time.Now().Unix())
}

func createClusterCmd() *cobra.Command {
cfg := &eks.ClusterConfig{}

cmd := &cobra.Command{
Use: "cluster",
Use: "cluster",
Short: "Create a custer",
Run: func(_ *cobra.Command, _ []string) {
if err := doCreateCluster(cfg); err != nil {
logger.Critical(err.Error())
Expand All @@ -55,11 +61,11 @@ func createClusterCmd() *cobra.Command {

fs := cmd.Flags()

fs.StringVarP(&cfg.ClusterName, "cluster-name", "n", "", fmt.Sprintf("EKS cluster name (generated, e.g. %q)", namer.RandomName()))
fs.StringVarP(&cfg.ClusterName, "cluster-name", "n", "", fmt.Sprintf("EKS cluster name (generated if unspecified, e.g. %q)", getClusterName()))
fs.StringVarP(&cfg.Region, "region", "r", DEFAULT_EKS_REGION, "AWS region")

fs.StringVarP(&cfg.NodeType, "node-type", "t", DEFAULT_NODE_TYPE, "node instance type")
fs.IntVarP(&cfg.Nodes, "nodes", "N", DEFAULT_NODE_COUNT, "total number of nodes for a fixed ASG")
fs.IntVarP(&cfg.Nodes, "nodes", "N", DEFAULT_NODE_COUNT, "total number of nodes (for a static ASG)")

// TODO(p2): review parameter validation, this shouldn't be needed initially
fs.IntVarP(&cfg.MinNodes, "nodes-min", "m", 0, "maximum nodes in ASG")
Expand All @@ -81,7 +87,7 @@ func doCreateCluster(cfg *eks.ClusterConfig) error {
}

if cfg.ClusterName == "" {
cfg.ClusterName = fmt.Sprintf("%s-%d", namer.RandomName(), time.Now().Unix())
cfg.ClusterName = getClusterName()
}

if cfg.SSHPublicKeyPath == "" {
Expand Down
6 changes: 4 additions & 2 deletions cmd/eksctl/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (

func deleteCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "delete",
Use: "delete",
Short: "Delete resource(s)",
Run: func(c *cobra.Command, _ []string) {
c.Help()
},
Expand All @@ -28,7 +29,8 @@ func deleteClusterCmd() *cobra.Command {
cfg := &eks.ClusterConfig{}

cmd := &cobra.Command{
Use: "cluster",
Use: "cluster",
Short: "Delete a cluster",
Run: func(_ *cobra.Command, _ []string) {
if err := doDeleteCluster(cfg); err != nil {
logger.Critical(err.Error())
Expand Down
4 changes: 3 additions & 1 deletion cmd/eksctl/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (

func getCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "get",
Use: "get",
Short: "Get resource(s)",
Run: func(c *cobra.Command, _ []string) {
c.Help()
},
Expand All @@ -28,6 +29,7 @@ func getClusterCmd() *cobra.Command {

cmd := &cobra.Command{
Use: "cluster",
Short: "Get custer(s)",
Aliases: []string{"clusters"},
Run: func(_ *cobra.Command, _ []string) {
if err := doGetCluster(cfg); err != nil {
Expand Down
5 changes: 3 additions & 2 deletions cmd/eksctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
)

var rootCmd = &cobra.Command{
Use: "eksctl",
Use: "eksctl",
Short: "a CLI for Amazon EKS",
Run: func(c *cobra.Command, _ []string) {
c.Help()
},
Expand All @@ -19,7 +20,7 @@ func init() {

addCommands()

rootCmd.PersistentFlags().IntVarP(&logger.Level, "verbose", "v", 3, "set log level")
rootCmd.PersistentFlags().IntVarP(&logger.Level, "verbose", "v", 3, "set log level, use 0 to silence and 4 for debugging")
rootCmd.PersistentFlags().BoolVarP(&logger.Color, "color", "C", true, "toggle colorized logs")
}

Expand Down

0 comments on commit 57871f4

Please sign in to comment.