cmdSchemas runs ghmock schemas update, which downloads both schema files again, to the files ghmock uses.
(args []string, stdout, stderr io.Writer)
| 685 | // cmdSchemas runs ghmock schemas update, which downloads both schema files |
| 686 | // again, to the files ghmock uses. |
| 687 | func cmdSchemas(args []string, stdout, stderr io.Writer) error { |
| 688 | switch { |
| 689 | case askedForHelp(args): |
| 690 | return flag.ErrHelp |
| 691 | case len(args) == 0: |
| 692 | return newUsageError("missing subcommand; use ghmock schemas update") |
| 693 | case args[0] != "update": |
| 694 | return newUsageError("unknown subcommand %q; use ghmock schemas update", args[0]) |
| 695 | case len(args) > 1: |
| 696 | return newUsageError("unexpected arguments: %s", strings.Join(args[1:], " ")) |
| 697 | } |
| 698 | var errs []error |
| 699 | for _, s := range []schemaSource{graphQLSource, restSource} { |
| 700 | p, err := s.updatePath() |
| 701 | if err == nil { |
| 702 | err = s.download(p, stderr) |
| 703 | } |
| 704 | if err != nil { |
| 705 | errs = append(errs, err) |
| 706 | continue |
| 707 | } |
| 708 | size := "" |
| 709 | if info, err := os.Stat(p); err == nil { |
| 710 | size = " (" + formatSize(info.Size()) + ")" |
| 711 | } |
| 712 | fmt.Fprintf(stdout, "%s: %s%s\n", s.label, p, size) |
| 713 | } |
| 714 | return errors.Join(errs...) |
| 715 | } |
| 716 | |
| 717 | func formatSize(n int64) string { |
| 718 | if n < 1<<20 { |