diff --git a/cmd/cammount/cammount.go b/cmd/cammount/cammount.go index ff33870c7..433b7e0ff 100644 --- a/cmd/cammount/cammount.go +++ b/cmd/cammount/cammount.go @@ -21,6 +21,7 @@ package main import ( "flag" "fmt" + "io/ioutil" "log" "net/http" "os" @@ -41,10 +42,11 @@ import ( var ( debug = flag.Bool("debug", false, "print debugging messages.") xterm = flag.Bool("xterm", false, "Run an xterm in the mounted directory. Shut down when xterm ends.") + open = flag.Bool("open", false, "Open a GUI window") ) func usage() { - fmt.Fprint(os.Stderr, "usage: cammount [opts] [|]\n") + fmt.Fprint(os.Stderr, "usage: cammount [opts] [ [|]]\n") flag.PrintDefaults() os.Exit(2) } @@ -57,11 +59,21 @@ func main() { flag.Parse() narg := flag.NArg() - if narg < 1 || narg > 2 { + if narg > 2 { usage() } - mountPoint := flag.Arg(0) + var mountPoint string + var err error + if narg > 0 { + mountPoint = flag.Arg(0) + } else { + mountPoint, err = ioutil.TempDir("", "cammount") + if err != nil { + log.Fatal(err) + } + defer os.Remove(mountPoint) + } errorf := func(msg string, args ...interface{}) { fmt.Fprintf(os.Stderr, msg, args...) @@ -146,6 +158,12 @@ func main() { defer cmd.Process.Kill() } } + if *open { + if runtime.GOOS == "darwin" { + cmd := exec.Command("open", mountPoint) + go cmd.Run() + } + } signal.Notify(sigc, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)