| 28 | } |
| 29 | |
| 30 | func parseSchemaArgs(args []string) (schemaOptions, error) { |
| 31 | var opts schemaOptions |
| 32 | fs := flag.NewFlagSet("schema", flag.ContinueOnError) |
| 33 | fs.SetOutput(io.Discard) |
| 34 | fs.StringVar(&opts.at, "at", "", "dotted path inside a REST body, such as user.login") |
| 35 | fs.IntVar(&opts.status, "status", 0, "which documented REST status to describe") |
| 36 | name, err := parseWithName(fs, args) |
| 37 | if err != nil { |
| 38 | return schemaOptions{}, err |
| 39 | } |
| 40 | opts.name = name |
| 41 | |
| 42 | switch { |
| 43 | case opts.name == "": |
| 44 | return schemaOptions{}, newUsageError("missing name, such as Issue, Issue.title or \"GET /repos/octo/hello\"") |
| 45 | case strings.HasPrefix(opts.name, "graphql "): |
| 46 | return schemaOptions{}, newUsageError("look up GraphQL types and fields by name, such as Issue or Issue.title") |
| 47 | case !opts.isREST() && (opts.at != "" || opts.status != 0): |
| 48 | return schemaOptions{}, newUsageError("--at and --status are for REST requests; look up a GraphQL field as Type.field") |
| 49 | case opts.status != 0 && (opts.status < 100 || opts.status > 599): |
| 50 | return schemaOptions{}, newUsageError("--status must be between 100 and 599") |
| 51 | } |
| 52 | if opts.isREST() { |
| 53 | if err := validateName(opts.name); err != nil { |
| 54 | return schemaOptions{}, usageError{err} |
| 55 | } |
| 56 | } |
| 57 | return opts, nil |
| 58 | } |
| 59 | |
| 60 | func cmdSchema(args []string, stdout, stderr io.Writer) error { |
| 61 | opts, err := parseSchemaArgs(args) |