bb/src/tool/ln/main.go

35 lines
484 B
Go
Raw Normal View History

2023-03-08 16:39:50 +03:00
package ln
import (
"fmt"
"os"
2023-03-24 19:47:31 +03:00
"github.com/surdeus/gomtool/src/mtool"
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]
var err error
if lflag {
err = os.Symlink(src, dst)
} else {
err = os.Link(src, dst)
}
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
}