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

Function parseWriteArgs

script/ghmock/gitcmd.go:105–124  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

103}
104
105func parseWriteArgs(args []string) (writeOptions, error) {
106 var opts writeOptions
107 fs := flag.NewFlagSet("write", flag.ContinueOnError)
108 fs.SetOutput(io.Discard)
109 fs.StringVar(&opts.text, "text", "", "file contents, including an empty string")
110 path, err := parseWithName(fs, args)
111 if err != nil {
112 return writeOptions{}, err
113 }
114 if !filepath.IsLocal(path) || filepath.Clean(path) == "." {
115 return writeOptions{}, newUsageError("pass a file path relative to the Git workspace")
116 }
117 hasText := false
118 fs.Visit(func(f *flag.Flag) { hasText = hasText || f.Name == "text" })
119 if !hasText {
120 return writeOptions{}, newUsageError("pass --text with the file contents")
121 }
122 opts.path = path
123 return opts, nil
124}
125
126func cmdWrite(args []string, stdout io.Writer) error {
127 opts, err := parseWriteArgs(args)

Callers 2

TestParseWriteArgsFunction · 0.85
cmdWriteFunction · 0.85

Calls 4

parseWithNameFunction · 0.85
newUsageErrorFunction · 0.85
IsLocalMethod · 0.65
CleanMethod · 0.45

Tested by 1

TestParseWriteArgsFunction · 0.68