diff --git a/src/cmd/goblin/main.go b/src/cmd/goblin/main.go index a7c49a6..20f2a3c 100644 --- a/src/cmd/goblin/main.go +++ b/src/cmd/goblin/main.go @@ -28,6 +28,7 @@ import( "github.com/surdeus/goblin/src/tool/path" "github.com/surdeus/goblin/src/tool/mk" "github.com/surdeus/goblin/src/tool/awk" + "github.com/surdeus/goblin/src/tool/paths" ) func main() { @@ -58,6 +59,10 @@ func main() { "path" : mtool.Tool{path.Run, "print cross platform path based on cmd arguments"}, "mk" : mtool.Tool{mk.Run, "file dependency system, simpler make"}, "awk" : mtool.Tool{awk.Run, "simple scripting language for working with string templates"}, + "paths" : mtool.Tool{ + paths.Run, + "convert UNIX slash separated paths into the OS compatible ones", + }, } mtool.Main("goblin", tools) diff --git a/src/tool/paths/main.go b/src/tool/paths/main.go new file mode 100644 index 0000000..364316a --- /dev/null +++ b/src/tool/paths/main.go @@ -0,0 +1,35 @@ +package paths + +import ( + "path/filepath" + "fmt" + "flag" + "bufio" + "os" +) + +var ( +) + +func handlePath(p string) { + fin := filepath.FromSlash(p) + fmt.Println(fin) +} + +func Run(args []string) { + arg0 := args[0] + args = args[1:] + flags := flag.NewFlagSet(arg0, flag.ExitOnError) + flags.Parse(args) + args = flags.Args() + + for _, p := range args { + handlePath(p) + } + + rd := bufio.NewScanner(os.Stdin) + for rd.Scan() { + handlePath(rd.Text()) + } +} +