You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
986 B
56 lines
986 B
5 years ago
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"os"
|
||
|
)
|
||
|
|
||
|
func logicalPWD() {
|
||
|
dir, err := os.Getwd()
|
||
|
if err != nil {
|
||
|
fmt.Printf("%v error: %v", os.Args[0], err)
|
||
|
os.Exit(1)
|
||
|
}
|
||
|
fmt.Println(dir)
|
||
|
}
|
||
|
|
||
|
func physicalPWD() {
|
||
|
fmt.Println("Using physical WD")
|
||
|
}
|
||
|
|
||
|
func usage() {
|
||
|
fmt.Printf("usage: %v [-LP]\n", os.Args[0])
|
||
|
}
|
||
|
|
||
|
// if there's bs in os.Args[2], it ignores everything else
|
||
|
func parseArgs() []string {
|
||
|
flags := []string{}
|
||
|
return flags
|
||
|
}
|
||
|
|
||
|
// usePhysical parses command-line arguments and determines which mode should be used.
|
||
|
// If both -L and -P are specified, the last one shall apply.
|
||
|
// If neither -L nor -P is specified, the pwd utility shall behave as if -L had been specified.
|
||
|
func usePhysical() bool {
|
||
|
if len(os.Args) > 1 {
|
||
|
flags := parseArgs()
|
||
|
flagsLen := len(flags)
|
||
|
lastFlag := flags[flagsLen]
|
||
|
if lastFlag == "L" {
|
||
|
return false
|
||
|
}
|
||
|
if lastFlag == "P" {
|
||
|
return true
|
||
|
}
|
||
|
}
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
if usePhysical() {
|
||
|
physicalPWD()
|
||
|
} else {
|
||
|
logicalPWD()
|
||
|
}
|
||
|
}
|