MCPcopy Create free account
hub / github.com/auth0/auth0-cli / createRuleCmd

Function createRuleCmd

internal/cli/rules.go:133–213  ·  view source on GitHub ↗
(cli *cli)

Source from the content-addressed store, hash-verified

131}
132
133func 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 }

Callers 1

rulesCmdFunction · 0.85

Calls 13

PipedInputFunction · 0.92
WaitingFunction · 0.92
ErrorfMethod · 0.80
SelectMethod · 0.80
labelsMethod · 0.80
OpenEditorMethod · 0.80
getValueMethod · 0.80
WarnfMethod · 0.80
RuleCreateMethod · 0.80
RegisterStringMethod · 0.80
RegisterBoolMethod · 0.80
CreateMethod · 0.65

Tested by

no test coverage detected