MCPcopy Create free account
hub / github.com/cli/cli / cmdSchemas

Function cmdSchemas

script/ghmock/schemacmd.go:687–715  ·  view source on GitHub ↗

cmdSchemas runs ghmock schemas update, which downloads both schema files again, to the files ghmock uses.

(args []string, stdout, stderr io.Writer)

Source from the content-addressed store, hash-verified

685// cmdSchemas runs ghmock schemas update, which downloads both schema files
686// again, to the files ghmock uses.
687func 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
717func formatSize(n int64) string {
718 if n < 1<<20 {

Callers 2

TestCmdSchemasFunction · 0.85
runMainFunction · 0.85

Calls 7

askedForHelpFunction · 0.85
newUsageErrorFunction · 0.85
formatSizeFunction · 0.85
JoinMethod · 0.80
updatePathMethod · 0.80
downloadMethod · 0.80
SizeMethod · 0.65

Tested by 1

TestCmdSchemasFunction · 0.68