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

Function cmdWrite

script/ghmock/gitcmd.go:126–152  ·  view source on GitHub ↗
(args []string, stdout io.Writer)

Source from the content-addressed store, hash-verified

124}
125
126func cmdWrite(args []string, stdout io.Writer) error {
127 opts, err := parseWriteArgs(args)
128 if err != nil {
129 return err
130 }
131 st, err := openState()
132 if err != nil {
133 return err
134 }
135 world, err := st.ensureGitFixture()
136 if err != nil {
137 return err
138 }
139 root, err := os.OpenRoot(filepath.Join(world, "work"))
140 if err != nil {
141 return err
142 }
143 defer root.Close()
144 if err := root.MkdirAll(filepath.Dir(opts.path), 0o755); err != nil {
145 return err
146 }
147 if err := root.WriteFile(opts.path, []byte(opts.text), 0o644); err != nil {
148 return err
149 }
150 fmt.Fprintf(stdout, "Wrote %s (%d bytes)\n", opts.path, len(opts.text))
151 return nil
152}
153
154type gitOptions struct {
155 in string

Callers 6

TestCmdWriteFunction · 0.85
TestCmdGitFunction · 0.85
prepareGitRepoFunction · 0.85
TestCmdExportFunction · 0.85
TestRunAllFunction · 0.85
runMainFunction · 0.85

Calls 7

parseWriteArgsFunction · 0.85
openStateFunction · 0.85
ensureGitFixtureMethod · 0.80
JoinMethod · 0.80
MkdirAllMethod · 0.80
WriteFileMethod · 0.80
CloseMethod · 0.65

Tested by 5

TestCmdWriteFunction · 0.68
TestCmdGitFunction · 0.68
prepareGitRepoFunction · 0.68
TestCmdExportFunction · 0.68
TestRunAllFunction · 0.68