| 103 | } |
| 104 | |
| 105 | func 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 | |
| 126 | func cmdWrite(args []string, stdout io.Writer) error { |
| 127 | opts, err := parseWriteArgs(args) |