Start making pwd

feature/pwd
dtluna 6 years ago
parent 35fa871fdb
commit 1db36f45d3
  1. 55
      pwd/pwd.go

@ -0,0 +1,55 @@
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()
}
}
Loading…
Cancel
Save