From 964e9b23037345fa710651b06c5c56023ca62151 Mon Sep 17 00:00:00 2001 From: surdeus Date: Thu, 30 Mar 2023 13:22:02 +0300 Subject: [PATCH] ... --- src/tool/ftest/main.go | 2 ++ src/tool/ln/main.go | 4 ++++ src/tool/useprog/main.go | 17 ++++++++++++++--- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/tool/ftest/main.go b/src/tool/ftest/main.go index a8f0b3a..a406c32 100644 --- a/src/tool/ftest/main.go +++ b/src/tool/ftest/main.go @@ -6,6 +6,7 @@ import ( "bufio" "fmt" "github.com/surdeus/gomtool/src/mtool" + "path/filepath" ) var ( @@ -67,6 +68,7 @@ func IsReadable(p string) bool { } func checkFile(p string) bool { + p = filepath.FromSlash(p) for _, v := range flagList { if !flagMap[v](p){ return false diff --git a/src/tool/ln/main.go b/src/tool/ln/main.go index 339e0dd..9f542c7 100644 --- a/src/tool/ln/main.go +++ b/src/tool/ln/main.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "github.com/surdeus/gomtool/src/mtool" + "path/filepath" ) func Run(flagSet *mtool.Flags) { @@ -20,6 +21,9 @@ func Run(flagSet *mtool.Flags) { src := args[0] dst := args[1] + + src = filepath.FromSlash(src) + dst = filepath.FromSlash(dst) var err error if lflag { diff --git a/src/tool/useprog/main.go b/src/tool/useprog/main.go index 0d8469b..5c3c648 100644 --- a/src/tool/useprog/main.go +++ b/src/tool/useprog/main.go @@ -1,12 +1,16 @@ package useprog import ( + "os" "os/exec" "fmt" "github.com/surdeus/gomtool/src/mtool" + "path/filepath" ) func Run(flagSet *mtool.Flags) { + var nVar bool + flagSet.BoolVar(&nVar, "n", false, "print only name, not path") flagSet.Parse() args := flagSet.Args() @@ -15,11 +19,18 @@ func Run(flagSet *mtool.Flags) { } for _, v := range args { - _, err := exec.LookPath(v) + pth, err := exec.LookPath(v) if err != nil { continue } - fmt.Printf("%s", v) - break + var toPrint string + if nVar { + toPrint = v + } else { + toPrint = filepath.ToSlash(pth) + } + fmt.Printf("%s", toPrint) + os.Exit(0) } + os.Exit(1) }