Skip to content

Commit

Permalink
Fix-up cmd args
Browse files Browse the repository at this point in the history
Closes #821
Also uses built-in cli validators rather than inline functions
  • Loading branch information
julienduchesne committed Mar 13, 2023
1 parent aa574ba commit e3ca179
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 28 deletions.
9 changes: 2 additions & 7 deletions cmd/tk/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var kubectlContexts = cli.PredictFunc(

func envSetCmd() *cli.Command {
cmd := &cli.Command{
Use: "set",
Use: "set <path>",
Short: "update properties of an environment",
Args: workflowArgs,
Predictors: complete.Flags{
Expand Down Expand Up @@ -234,12 +234,7 @@ func envRemoveCmd() *cli.Command {

func envListCmd() *cli.Command {
args := workflowArgs
args.Validator = cli.ValidateFunc(func(args []string) error {
if len(args) > 1 {
return fmt.Errorf("expects at most 1 arg, received %v", len(args))
}
return nil
})
args.Validator = cli.ArgsRange(0, 1)

cmd := &cli.Command{
Use: "list [<path>]",
Expand Down
7 changes: 1 addition & 6 deletions cmd/tk/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ import (

func exportCmd() *cli.Command {
args := workflowArgs
args.Validator = cli.ValidateFunc(func(args []string) error {
if len(args) < 2 {
return fmt.Errorf("expects at least 2 args, received %v", len(args))
}
return nil
})
args.Validator = cli.ArgsMin(2)

cmd := &cli.Command{
Use: "export <outputDir> <path> [<path>...]",
Expand Down
8 changes: 1 addition & 7 deletions cmd/tk/fmt.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"errors"
"fmt"
"io"
"os"
Expand All @@ -21,12 +20,7 @@ func fmtCmd() *cli.Command {
Use: "fmt <FILES|DIRECTORIES>",
Short: "format Jsonnet code",
Args: cli.Args{
Validator: cli.ValidateFunc(func(args []string) error {
if len(args) == 0 {
return errors.New("at least one file or directory is required")
}
return nil
}),
Validator: cli.ArgsMin(1),
Predictor: complete.PredictFiles("*.*sonnet"),
},
}
Expand Down
9 changes: 1 addition & 8 deletions cmd/tk/lint.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package main

import (
"errors"

"github.com/go-clix/cli"
"github.com/gobwas/glob"
"github.com/posener/complete"
Expand All @@ -15,12 +13,7 @@ func lintCmd() *cli.Command {
Use: "lint <FILES|DIRECTORIES>",
Short: "lint Jsonnet code",
Args: cli.Args{
Validator: cli.ValidateFunc(func(args []string) error {
if len(args) == 0 {
return errors.New("at least one file or directory is required")
}
return nil
}),
Validator: cli.ArgsMin(1),
Predictor: complete.PredictFiles("*.*sonnet"),
},
}
Expand Down

0 comments on commit e3ca179

Please sign in to comment.