mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-04 07:29:56 +08:00
41 lines
720 B
Go
41 lines
720 B
Go
package commands
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
type CpOptions struct{}
|
|
|
|
func Cp(_ *CpOptions) error {
|
|
DisableFooter = true
|
|
|
|
// 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
|
|
}
|