From bf4a14cecc392b2e4e23ae5d016f773514a972e9 Mon Sep 17 00:00:00 2001 From: Alexis Kulash Date: Mon, 25 Jan 2021 14:34:26 -0500 Subject: [PATCH] WIP: Adding initial base for a new "create rule" subcommand --- internal/cli/rules.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/internal/cli/rules.go b/internal/cli/rules.go index f3bb6bce3..1e7fd51e0 100644 --- a/internal/cli/rules.go +++ b/internal/cli/rules.go @@ -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", @@ -12,6 +15,8 @@ func rulesCmd(cli *cli) *cobra.Command { cmd.SetUsageTemplate(resourceUsageTemplate()) cmd.AddCommand(listRulesCmd(cli)) + cmd.AddCommand(createRulesCmd(cli)) + return cmd } @@ -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 +}