init commit.
This commit is contained in:
33
util_cli_path.go
Normal file
33
util_cli_path.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func PathOrPWD() (p string, fi os.FileInfo) {
|
||||
if len(os.Args) != 1 {
|
||||
p = strings.Join(os.Args[1:], " ")
|
||||
} else {
|
||||
pwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
panic("Check if $PWD exist?")
|
||||
}
|
||||
p = pwd
|
||||
}
|
||||
|
||||
p, err := filepath.Abs(p)
|
||||
if err != nil {
|
||||
panic("Path not exist: " + p)
|
||||
}
|
||||
|
||||
fi, err = os.Stat(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("Working path: " + p)
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user