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

Function cmdExport

script/ghmock/export.go:47–98  ·  view source on GitHub ↗

cmdExport writes everything needed to check a result to a folder or archive: each run's command, output and report, every request with the response gh got, the stored responses, and the schema files the checks used.

(args []string, stdout io.Writer)

Source from the content-addressed store, hash-verified

45// run's command, output and report, every request with the response gh got,
46// the stored responses, and the schema files the checks used.
47func cmdExport(args []string, stdout io.Writer) error {
48 opts, err := parseExportArgs(args)
49 if err != nil {
50 return err
51 }
52 st, err := openState()
53 if err != nil {
54 return err
55 }
56 runs, err := st.readRuns()
57 if err != nil {
58 return err
59 }
60 if len(runs) == 0 {
61 return errors.New("nothing to export yet; run gh with ghmock run first")
62 }
63 entries, err := st.readLog()
64 if err != nil {
65 return err
66 }
67 responses, err := st.loadResponses()
68 if err != nil {
69 return err
70 }
71 write := func(dir string) error {
72 return writeExportDir(st, dir, runs, entries, responses)
73 }
74 if opts.archive {
75 err = writeExportArchive(opts.path, write)
76 } else {
77 err = write(opts.path)
78 }
79 if err != nil {
80 return err
81 }
82
83 total, offSchema := 0, 0
84 for _, list := range responses {
85 for _, r := range list {
86 total++
87 if r.OffSchema {
88 offSchema++
89 }
90 }
91 }
92 summary := fmt.Sprintf("Exported %s, %s and %s", plural(len(runs), "run"), plural(len(entries), "request"), plural(total, "response"))
93 if offSchema > 0 {
94 summary += fmt.Sprintf(", %d off-schema,", offSchema)
95 }
96 fmt.Fprintf(stdout, "%s to %s\n", summary, opts.path)
97 return nil
98}
99
100func writeExportDir(st *state, dir string, runs []runRecord, entries []loggedRequest, responses responseSet) error {
101 if err := prepareExportDir(dir); err != nil {

Callers 3

TestCmdExportFunction · 0.85
TestRunAllFunction · 0.85
runMainFunction · 0.85

Calls 8

parseExportArgsFunction · 0.85
openStateFunction · 0.85
writeExportDirFunction · 0.85
writeExportArchiveFunction · 0.85
pluralFunction · 0.85
readRunsMethod · 0.80
readLogMethod · 0.80
loadResponsesMethod · 0.80

Tested by 2

TestCmdExportFunction · 0.68
TestRunAllFunction · 0.68