Simplify FileContentFlag.

This commit is contained in:
Alec Thomas
2018-10-25 12:53:55 -07:00
parent 119a0d115b
commit c0df056b14
2 changed files with 3 additions and 8 deletions
+2 -6
View File
@@ -474,10 +474,7 @@ func JoinEscaped(s []string, sep rune) string {
} }
// FileContentFlag is a flag value that loads a file's contents into its value. // FileContentFlag is a flag value that loads a file's contents into its value.
type FileContentFlag struct { type FileContentFlag []byte
Path string
Data []byte
}
func (f *FileContentFlag) Decode(ctx *DecodeContext) error { // nolint: golint func (f *FileContentFlag) Decode(ctx *DecodeContext) error { // nolint: golint
filename := ctx.Scan.PopValue("filename") filename := ctx.Scan.PopValue("filename")
@@ -485,7 +482,6 @@ func (f *FileContentFlag) Decode(ctx *DecodeContext) error { // nolint: golint
if err != nil { if err != nil {
return fmt.Errorf("failed to open %q: %s", filename, err) return fmt.Errorf("failed to open %q: %s", filename, err)
} }
f.Path = filename *f = data
f.Data = data
return nil return nil
} }
+1 -2
View File
@@ -164,6 +164,5 @@ func TestFileContentFlag(t *testing.T) {
f.Close() f.Close()
_, err = mustNew(t, &cli).Parse([]string{"--file", f.Name()}) _, err = mustNew(t, &cli).Parse([]string{"--file", f.Name()})
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, []byte("hello world"), cli.File.Data) require.Equal(t, []byte("hello world"), []byte(cli.File))
require.Equal(t, f.Name(), cli.File.Path)
} }