2023-03-08 16:39:50 +03:00
|
|
|
package ln
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2024-05-15 21:07:35 +03:00
|
|
|
"surdeus.su/core/cli/mtool"
|
2023-03-30 13:22:02 +03:00
|
|
|
"path/filepath"
|
2023-03-08 16:39:50 +03:00
|
|
|
)
|
|
|
|
|
2023-03-24 19:47:31 +03:00
|
|
|
func Run(flagSet *mtool.Flags) {
|
2023-03-08 16:39:50 +03:00
|
|
|
var lflag bool
|
|
|
|
flagSet.BoolVar(&lflag, "s", false, "make a symbolic link, not a hard one")
|
|
|
|
|
2023-03-24 19:47:31 +03:00
|
|
|
flagSet.Parse()
|
|
|
|
args := flagSet.Args()
|
2023-03-08 16:39:50 +03:00
|
|
|
|
|
|
|
if len(args) != 2 {
|
|
|
|
flagSet.Usage()
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
src := args[0]
|
|
|
|
dst := args[1]
|
2023-03-30 13:22:02 +03:00
|
|
|
|
|
|
|
src = filepath.FromSlash(src)
|
|
|
|
dst = filepath.FromSlash(dst)
|
2023-03-08 16:39:50 +03:00
|
|
|
|
|
|
|
var err error
|
|
|
|
if lflag {
|
|
|
|
err = os.Symlink(src, dst)
|
|
|
|
} else {
|
|
|
|
err = os.Link(src, dst)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
}
|
|
|
|
}
|