Skip to content

Commit

Permalink
WIP: Adding initial base for a new "create rule" subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexis Kulash committed Jan 25, 2021
1 parent d85ff3c commit bf4a14c
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions internal/cli/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"github.com/spf13/cobra"
)

var name, script, order string
var enable bool

func rulesCmd(cli *cli) *cobra.Command {
cmd := &cobra.Command{
Use: "rules",
Expand All @@ -12,6 +15,8 @@ func rulesCmd(cli *cli) *cobra.Command {

cmd.SetUsageTemplate(resourceUsageTemplate())
cmd.AddCommand(listRulesCmd(cli))
cmd.AddCommand(createRulesCmd(cli))

return cmd
}

Expand All @@ -34,3 +39,33 @@ func listRulesCmd(cli *cli) *cobra.Command {

return cmd
}

func createRulesCmd(cli *cli) *cobra.Command {
cmd := &cobra.Command{
Use: "create [OPTIONS]",
TraverseChildren: true,
Short: "Create a new rule",
Long: "Create a new rule in your current tenant.",
Args: cobra.MinimumNArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
// TODO: Add the proper functionality here -- currently not working
err := cli.api.Client.Rule.Create()

if err != nil {
return err
}

cli.renderer.Infof("Your rule `%s` was successfully created.", args[0])
return nil
},
}

cmd.Flags().StringVarP(&name, "name", "n", "", "Name of this rule (required)")
cmd.Flags().StringVarP(&script, "script", "s", "", "Code to be executed when this rule runs (required)")
cmd.Flags().StringVarP(&order, "order", "o", "", "Order that this rule should execute in relative to other rules. Lower-valued rules execute first.")
cmd.Flags().BoolVarP(&enable, "enable", "e", false, "Whether the rule is enabled (true), or disabled (false).")
cmd.MarkFlagRequired("name")
cmd.MarkFlagRequired("script")

return cmd
}

0 comments on commit bf4a14c

Please sign in to comment.