From c0df056b1463b3b6823e2981e21704fc2b47a596 Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Thu, 25 Oct 2018 12:53:55 -0700 Subject: [PATCH] Simplify FileContentFlag. --- mapper.go | 8 ++------ mapper_test.go | 3 +-- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/mapper.go b/mapper.go index 322ab46..e4d54fd 100644 --- a/mapper.go +++ b/mapper.go @@ -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. -type FileContentFlag struct { - Path string - Data []byte -} +type FileContentFlag []byte func (f *FileContentFlag) Decode(ctx *DecodeContext) error { // nolint: golint filename := ctx.Scan.PopValue("filename") @@ -485,7 +482,6 @@ func (f *FileContentFlag) Decode(ctx *DecodeContext) error { // nolint: golint if err != nil { return fmt.Errorf("failed to open %q: %s", filename, err) } - f.Path = filename - f.Data = data + *f = data return nil } diff --git a/mapper_test.go b/mapper_test.go index 04a1d93..6d393ad 100644 --- a/mapper_test.go +++ b/mapper_test.go @@ -164,6 +164,5 @@ func TestFileContentFlag(t *testing.T) { f.Close() _, err = mustNew(t, &cli).Parse([]string{"--file", f.Name()}) require.NoError(t, err) - require.Equal(t, []byte("hello world"), cli.File.Data) - require.Equal(t, f.Name(), cli.File.Path) + require.Equal(t, []byte("hello world"), []byte(cli.File)) }