34 lines
459 B
Go
34 lines
459 B
Go
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
|
|
}
|