-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.go
57 lines (48 loc) · 971 Bytes
/
helper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"io"
"os"
"github.com/alexflint/go-arg"
)
func writeHelp(config any, output io.Writer) error {
parser, err := arg.NewParser(arg.Config{}, config)
if err != nil {
return err
}
parser.WriteHelp(output)
return nil
}
func copyFile(src, dst string) error {
// Open the source file for reading
srcFile, err := os.Open(src)
if err != nil {
return err
}
defer srcFile.Close()
// Create the destination file
dstFile, err := os.Create(dst)
if err != nil {
return err
}
defer dstFile.Close()
// Copy the contents of the source file to the destination file
_, err = io.Copy(dstFile, srcFile)
if err != nil {
return err
}
// Sync the written content to the disk
err = dstFile.Sync()
if err != nil {
return err
}
// Set the same permissions as the source file
srcFileInfo, err := srcFile.Stat()
if err != nil {
return err
}
err = os.Chmod(dst, srcFileInfo.Mode())
if err != nil {
return err
}
return nil
}