diff --git a/clidocstool.go b/clidocstool.go index 79a44a1..9dfb800 100644 --- a/clidocstool.go +++ b/clidocstool.go @@ -88,21 +88,17 @@ func fileExists(f string) bool { return !info.IsDir() } -func copyFile(src string, dest string) error { - srcFile, err := os.Open(src) +func copyFile(src string, dst string) error { + sf, err := os.Open(src) if err != nil { return err } - defer srcFile.Close() - - destFile, err := os.Create(dest) + defer sf.Close() + df, err := os.OpenFile(dst, os.O_CREATE|os.O_WRONLY, 0o600) if err != nil { return err } - defer destFile.Close() - - if _, err = io.Copy(destFile, srcFile); err != nil { - return err - } - return destFile.Sync() + defer df.Close() + _, err = io.Copy(df, sf) + return err } diff --git a/clidocstool_md_test.go b/clidocstool_md_test.go index 0b00aa7..afc3828 100644 --- a/clidocstool_md_test.go +++ b/clidocstool_md_test.go @@ -31,6 +31,9 @@ func TestGenMarkdownTree(t *testing.T) { require.NoError(t, err) defer os.RemoveAll(tmpdir) + err = copyFile(path.Join("fixtures", "buildx_stop.pre.md"), path.Join(tmpdir, "buildx_stop.md")) + require.NoError(t, err) + c, err := New(Options{ Root: buildxCmd, SourceDir: tmpdir, diff --git a/clidocstool_test.go b/clidocstool_test.go index 4731300..d0440d4 100644 --- a/clidocstool_test.go +++ b/clidocstool_test.go @@ -110,6 +110,9 @@ func TestGenAllTree(t *testing.T) { require.NoError(t, err) defer os.RemoveAll(tmpdir) + err = copyFile(path.Join("fixtures", "buildx_stop.pre.md"), path.Join(tmpdir, "buildx_stop.md")) + require.NoError(t, err) + c, err := New(Options{ Root: buildxCmd, SourceDir: tmpdir, diff --git a/fixtures/buildx_stop.pre.md b/fixtures/buildx_stop.pre.md new file mode 100644 index 0000000..77bbc03 --- /dev/null +++ b/fixtures/buildx_stop.pre.md @@ -0,0 +1,5 @@ +# docker buildx stop + + + +