5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-05 06:12:02 +08:00
wails/v3/internal/commands/tool_cp.go
2024-01-29 21:29:16 +11:00

39 lines
703 B
Go

package commands
import (
"fmt"
"os"
"path/filepath"
)
type CpOptions struct{}
func Cp(options *CpOptions) error {
// extract the source and destination from os.Args
if len(os.Args) != 5 {
return fmt.Errorf("cp requires a source and destination")
}
// Extract source
source := os.Args[3]
for _, destination := range os.Args[4:] {
src, err := filepath.Abs(source)
if err != nil {
return err
}
dst, err := filepath.Abs(destination)
if err != nil {
return err
}
input, err := os.ReadFile(src)
if err != nil {
return err
}
err = os.WriteFile(dst, input, 0644)
if err != nil {
return fmt.Errorf("error creating %s: %s", dst, err.Error())
}
}
return nil
}