| 53 | ` |
| 54 | |
| 55 | func encodeCmd() command { |
| 56 | encs := "[" + strings.Join([]string{encodingCSV, encodingGob, encodingJSON}, ", ") + "]" |
| 57 | fs := flag.NewFlagSet("vegeta encode", flag.ExitOnError) |
| 58 | to := fs.String("to", encodingJSON, "Output encoding "+encs) |
| 59 | output := fs.String("output", "stdout", "Output file") |
| 60 | |
| 61 | fs.Usage = func() { |
| 62 | fmt.Fprintf(os.Stderr, "%s\n", encodeUsage) |
| 63 | } |
| 64 | |
| 65 | return command{fs, func(args []string) error { |
| 66 | fs.Parse(args) |
| 67 | files := fs.Args() |
| 68 | if len(files) == 0 { |
| 69 | files = append(files, "stdin") |
| 70 | } |
| 71 | return encode(files, *to, *output) |
| 72 | }} |
| 73 | } |
| 74 | |
| 75 | func encode(files []string, to, output string) error { |
| 76 | dec, mc, err := decoder(files) |