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"
"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

View file

@ -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 {

View file

@ -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)
}