2022-11-21 01:27:21 +03:00
|
|
|
package useprog
|
|
|
|
|
|
|
|
import (
|
2023-03-30 13:22:02 +03:00
|
|
|
"os"
|
2022-11-21 01:27:21 +03:00
|
|
|
"os/exec"
|
|
|
|
"fmt"
|
2024-05-15 21:07:35 +03:00
|
|
|
"surdeus.su/core/cli/mtool"
|
2023-03-30 13:22:02 +03:00
|
|
|
"path/filepath"
|
2022-11-21 01:27:21 +03:00
|
|
|
)
|
|
|
|
|
2023-03-24 19:47:31 +03:00
|
|
|
func Run(flagSet *mtool.Flags) {
|
2023-03-30 13:22:02 +03:00
|
|
|
var nVar bool
|
|
|
|
flagSet.BoolVar(&nVar, "n", false, "print only name, not path")
|
2023-03-24 19:47:31 +03:00
|
|
|
flagSet.Parse()
|
|
|
|
args := flagSet.Args()
|
2022-11-21 01:27:21 +03:00
|
|
|
|
2023-03-24 19:47:31 +03:00
|
|
|
if len(args) < 1 {
|
2022-11-21 01:27:21 +03:00
|
|
|
flagSet.Usage()
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range args {
|
2023-03-30 13:22:02 +03:00
|
|
|
pth, err := exec.LookPath(v)
|
2022-11-21 01:27:21 +03:00
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
2023-03-30 13:22:02 +03:00
|
|
|
var toPrint string
|
|
|
|
if nVar {
|
|
|
|
toPrint = v
|
|
|
|
} else {
|
|
|
|
toPrint = filepath.ToSlash(pth)
|
|
|
|
}
|
|
|
|
fmt.Printf("%s", toPrint)
|
|
|
|
os.Exit(0)
|
2022-11-21 01:27:21 +03:00
|
|
|
}
|
2023-03-30 13:22:02 +03:00
|
|
|
os.Exit(1)
|
2022-11-21 01:27:21 +03:00
|
|
|
}
|