diff --git a/mapper.go b/mapper.go index 15ab88d..96e0185 100644 --- a/mapper.go +++ b/mapper.go @@ -465,7 +465,10 @@ func JoinEscaped(s []string, sep rune) string { } // FileContentFlag is a flag value that loads a file's contents into its value. -type FileContentFlag []byte +type FileContentFlag struct { + Path string + Data []byte +} func (f *FileContentFlag) Decode(ctx *DecodeContext) error { // nolint: golint filename := ctx.Scan.PopValue("filename") @@ -473,6 +476,7 @@ func (f *FileContentFlag) Decode(ctx *DecodeContext) error { // nolint: golint if err != nil { return fmt.Errorf("failed to open %q: %s", filename, err) } - *f = FileContentFlag(data) + f.Path = filename + f.Data = data return nil } diff --git a/mapper_test.go b/mapper_test.go index 6d393ad..04a1d93 100644 --- a/mapper_test.go +++ b/mapper_test.go @@ -164,5 +164,6 @@ 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"), []byte(cli.File)) + require.Equal(t, []byte("hello world"), cli.File.Data) + require.Equal(t, f.Name(), cli.File.Path) }