This commit is contained in:
Andrey Parhomenko 2023-03-30 13:22:02 +03:00
parent fab51f61ac
commit 964e9b2303
3 changed files with 20 additions and 3 deletions

View file

@ -6,6 +6,7 @@ import (
"bufio" "bufio"
"fmt" "fmt"
"github.com/surdeus/gomtool/src/mtool" "github.com/surdeus/gomtool/src/mtool"
"path/filepath"
) )
var ( var (
@ -67,6 +68,7 @@ func IsReadable(p string) bool {
} }
func checkFile(p string) bool { func checkFile(p string) bool {
p = filepath.FromSlash(p)
for _, v := range flagList { for _, v := range flagList {
if !flagMap[v](p){ if !flagMap[v](p){
return false return false

View file

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"os" "os"
"github.com/surdeus/gomtool/src/mtool" "github.com/surdeus/gomtool/src/mtool"
"path/filepath"
) )
func Run(flagSet *mtool.Flags) { func Run(flagSet *mtool.Flags) {
@ -21,6 +22,9 @@ func Run(flagSet *mtool.Flags) {
src := args[0] src := args[0]
dst := args[1] dst := args[1]
src = filepath.FromSlash(src)
dst = filepath.FromSlash(dst)
var err error var err error
if lflag { if lflag {
err = os.Symlink(src, dst) err = os.Symlink(src, dst)

View file

@ -1,12 +1,16 @@
package useprog package useprog
import ( import (
"os"
"os/exec" "os/exec"
"fmt" "fmt"
"github.com/surdeus/gomtool/src/mtool" "github.com/surdeus/gomtool/src/mtool"
"path/filepath"
) )
func Run(flagSet *mtool.Flags) { func Run(flagSet *mtool.Flags) {
var nVar bool
flagSet.BoolVar(&nVar, "n", false, "print only name, not path")
flagSet.Parse() flagSet.Parse()
args := flagSet.Args() args := flagSet.Args()
@ -15,11 +19,18 @@ func Run(flagSet *mtool.Flags) {
} }
for _, v := range args { for _, v := range args {
_, err := exec.LookPath(v) pth, err := exec.LookPath(v)
if err != nil { if err != nil {
continue continue
} }
fmt.Printf("%s", v) var toPrint string
break if nVar {
toPrint = v
} else {
toPrint = filepath.ToSlash(pth)
}
fmt.Printf("%s", toPrint)
os.Exit(0)
} }
os.Exit(1)
} }