(cli *cli)
| 131 | } |
| 132 | |
| 133 | func createRuleCmd(cli *cli) *cobra.Command { |
| 134 | var inputs struct { |
| 135 | Name string |
| 136 | Template string |
| 137 | Script string |
| 138 | Enabled bool |
| 139 | } |
| 140 | |
| 141 | cmd := &cobra.Command{ |
| 142 | Use: "create", |
| 143 | Args: cobra.NoArgs, |
| 144 | Short: "Create a new rule", |
| 145 | Long: rulesDeprecationDocumentationText + "Create a new rule.\n\n" + |
| 146 | "To create interactively, use `auth0 rules create` with no arguments.\n\n" + |
| 147 | "To create non-interactively, supply the name, template and other information through the flags.", |
| 148 | Example: ` auth0 rules create |
| 149 | auth0 rules create --enabled=true |
| 150 | auth0 rules create --enabled=true --name "My Rule" |
| 151 | auth0 rules create --enabled=false --name "My Rule" --template "Empty rule" |
| 152 | auth0 rules create --enabled=true --name "My Rule" --template "Empty rule" --script "$(cat path/to/script.js)" |
| 153 | auth0 rules create -e=true -n "My Rule" -t "Empty rule" -s "$(cat path/to/script.js)" --json |
| 154 | auth0 rules create -e=true -n "My Rule" -t "Empty rule" -s "$(cat path/to/script.js)" --json-compact |
| 155 | echo "{\"name\":\"piping-name\",\"script\":\"console.log('test')\"}" | auth0 rules create`, |
| 156 | RunE: func(cmd *cobra.Command, args []string) error { |
| 157 | rule := &management.Rule{} |
| 158 | pipedInput := iostream.PipedInput() |
| 159 | |
| 160 | if len(pipedInput) > 0 { |
| 161 | err := json.Unmarshal(pipedInput, rule) |
| 162 | if err != nil { |
| 163 | return fmt.Errorf("failed to unmarshal JSON input: %w", err) |
| 164 | } |
| 165 | } else { |
| 166 | if err := ruleName.Ask(cmd, &inputs.Name, nil); err != nil { |
| 167 | return err |
| 168 | } |
| 169 | |
| 170 | if err := ruleTemplate.Select(cmd, &inputs.Template, ruleTemplateOptions.labels(), nil); err != nil { |
| 171 | return err |
| 172 | } |
| 173 | |
| 174 | err := ruleScript.OpenEditor( |
| 175 | cmd, |
| 176 | &inputs.Script, |
| 177 | ruleTemplateOptions.getValue(inputs.Template), |
| 178 | inputs.Name+".*.js", |
| 179 | cli.ruleEditorHint, |
| 180 | ) |
| 181 | if err != nil { |
| 182 | return fmt.Errorf("failed to capture input from the editor: %w", err) |
| 183 | } |
| 184 | |
| 185 | rule = &management.Rule{ |
| 186 | Name: &inputs.Name, |
| 187 | Script: auth0.String(inputs.Script), |
| 188 | Enabled: &inputs.Enabled, |
| 189 | } |
| 190 | } |
no test coverage detected