validateName checks that a request name looks like "graphql Operation" or "METHOD /path".
(name string)
| 133 | // validateName checks that a request name looks like "graphql Operation" or |
| 134 | // "METHOD /path". |
| 135 | func validateName(name string) error { |
| 136 | method, target, ok := strings.Cut(name, " ") |
| 137 | if !ok || target == "" || strings.ContainsAny(target, " \t") { |
| 138 | return fmt.Errorf("request name %q must look like \"GET /repos/octo/hello\" or \"graphql IssueByNumber\"", name) |
| 139 | } |
| 140 | if method == "graphql" { |
| 141 | return nil |
| 142 | } |
| 143 | if strings.ToUpper(method) != method || strings.Trim(method, "ABCDEFGHIJKLMNOPQRSTUVWXYZ") != "" { |
| 144 | return fmt.Errorf("request name %q must start with an uppercase HTTP method or \"graphql\"", name) |
| 145 | } |
| 146 | if !strings.Contains(target, "/") { |
| 147 | return fmt.Errorf("request name %q must include a path, such as /repos/octo/hello", name) |
| 148 | } |
| 149 | return nil |
| 150 | } |
| 151 | |
| 152 | func cmdSet(args []string, stdout, stderr io.Writer) error { |
| 153 | opts, err := parseSetArgs(args) |
no test coverage detected