func recv(x *cli.Context) { defer func() { if r := recover(); r != nil { fatalf("error, likely due to missing server or misspelled anchor: %v", r) } }() c := dial(x) args := x.Args() if len(args) != 1 { fatalf("recv needs one anchor argument") } w, _ := parseGlob(args[0]) u, ok := c.Walk(w).Get().(client.Chan) if !ok { fatalf("not a channel") } msgr, err := u.Recv() if err != nil { fatalf("recv error: %v", err) } io.Copy(os.Stdout, msgr) // if _, err = io.Copy(os.Stdout, msgr); err != nil { // fatalf("transmission error: %v", err) // } }
func mkdkr(x *cli.Context) { defer func() { if r := recover(); r != nil { fatalf("error, likely due to missing server or misspelled anchor: %v", r) } }() c := dial(x) args := x.Args() if len(args) != 1 { fatalf("mkdkr needs an anchor argument") } w, _ := parseGlob(args[0]) buf, _ := ioutil.ReadAll(os.Stdin) var run docker.Run if err := json.Unmarshal(buf, &run); err != nil { fatalf("command json not parsing: %v", err) } if x.Bool("scrub") { run.Scrub = true } _, err := c.Walk(w).MakeDocker(run) if err != nil { fatalf("mkdkr error: %s", err) } }
func wait(x *cli.Context) { defer func() { if r := recover(); r != nil { fatalf("error, likely due to missing server or misspelled anchor: %v", r) } }() c := dial(x) args := x.Args() if len(args) != 1 { fatalf("wait needs one anchor argument") } w, _ := parseGlob(args[0]) // var stat interface{} var err error switch u := c.Walk(w).Get().(type) { case client.Proc: stat, err = u.Wait() case docker.Container: stat, err = u.Wait() default: fatalf("anchor is not a process or a docker container") } if err != nil { fatalf("wait error: %v", err) } buf, _ := json.MarshalIndent(stat, "", "\t") fmt.Println(string(buf)) }
// circuit mkproc /X1234/hola/charlie << EOF // { … } // EOF // TODO: Proc element disappears if command misspelled and error condition not obvious. func mkproc(x *cli.Context) { defer func() { if r := recover(); r != nil { fatalf("error, likely due to missing server or misspelled anchor: %v", r) } }() c := dial(x) args := x.Args() if len(args) != 1 { fatalf("mkproc needs an anchor argument") } w, _ := parseGlob(args[0]) buf, _ := ioutil.ReadAll(os.Stdin) var cmd client.Cmd if err := json.Unmarshal(buf, &cmd); err != nil { fatalf("command json not parsing: %v", err) } p, err := c.Walk(w).MakeProc(cmd) if err != nil { fatalf("mkproc error: %s", err) } ps := p.Peek() if ps.Exit != nil { fatalf("%v", ps.Exit) } }
func stdin(x *cli.Context) { defer func() { if r := recover(); r != nil { fatalf("error, likely due to missing server or misspelled anchor: %v", r) } }() c := dial(x) args := x.Args() if len(args) != 1 { fatalf("stdin needs one anchor argument") } w, _ := parseGlob(args[0]) u, ok := c.Walk(w).Get().(interface { Stdin() io.WriteCloser }) if !ok { fatalf("not a process or a container") } q := u.Stdin() if _, err := io.Copy(q, os.Stdin); err != nil { fatalf("transmission error: %v", err) } if err := q.Close(); err != nil { fatalf("error closing stdin: %v", err) } }
// circuit peek /X1234/hola/charlie func peek(x *cli.Context) { defer func() { if r := recover(); r != nil { fatalf("error, likely due to missing server or misspelled anchor: %v", r) } }() c := dial(x) args := x.Args() if len(args) != 1 { fatalf("peek needs one anchor argument") } w, _ := parseGlob(args[0]) switch t := c.Walk(w).Get().(type) { case client.Server: buf, _ := json.MarshalIndent(t.Peek(), "", "\t") fmt.Println(string(buf)) case client.Chan: buf, _ := json.MarshalIndent(t.Stat(), "", "\t") fmt.Println(string(buf)) case client.Proc: buf, _ := json.MarshalIndent(t.Peek(), "", "\t") fmt.Println(string(buf)) case client.Subscription: buf, _ := json.MarshalIndent(t.Peek(), "", "\t") fmt.Println(string(buf)) case nil: buf, _ := json.MarshalIndent(nil, "", "\t") fmt.Println(string(buf)) default: fatalf("unknown element") } }
func join(x *cli.Context) { defer func() { if r := recover(); r != nil { fatalf("error, likely due to missing server or misspelled anchor: %v", r) } }() c := dial(x) args := x.Args() if len(args) != 2 { fatalf("join needs one anchor argument and one circuit address argument") } // Verify the target circuit address is valid if _, err := n.ParseAddr(args[1]); err != nil { fatalf("argument %q is not a valid circuit address", args[1]) } // w, _ := parseGlob(args[0]) switch u := c.Walk(w).Get().(type) { case client.Server: if err := u.Rejoin(args[1]); err != nil { fatalf("error: %v", err) } default: fatalf("not a server") } }
func recv(x *cli.Context) { defer func() { if r := recover(); r != nil { fatalf("error, likely due to missing server or misspelled anchor: %v", r) } }() c := dial(x) args := x.Args() if len(args) != 1 { fatalf("recv needs one anchor argument") } w, _ := parseGlob(args[0]) switch u := c.Walk(w).Get().(type) { case client.Chan: msgr, err := u.Recv() if err != nil { fatalf("recv error: %v", err) } io.Copy(os.Stdout, msgr) case client.Subscription: v, ok := u.Consume() if !ok { fatalf("eof") } fmt.Println(v) os.Stdout.Sync() default: fatalf("not a channel or subscription") } }
func scrb(x *cli.Context) { defer func() { if r := recover(); r != nil { fatalf("error, likely due to missing server or misspelled anchor: %v", r) } }() c := dial(x) args := x.Args() if len(args) != 1 { fatalf("scrub needs one anchor argument") } w, _ := parseGlob(args[0]) c.Walk(w).Scrub() }
// circuit ls /Q123/apps/charlie // circuit ls /... func ls(x *cli.Context) { defer func() { if r := recover(); r != nil { fatalf("error, likely due to missing server or misspelled anchor: %v", r) } }() c := dial(x) args := x.Args() if len(args) != 1 { println("ls needs a glob argument") os.Exit(1) } w, ellipses := parseGlob(args[0]) list(0, "/", c.Walk(w), ellipses, x.Bool("long"), x.Bool("depth")) }
func clos(x *cli.Context) { c := dial(x) args := x.Args() if len(args) != 1 { fatalf("close needs one anchor argument") } w, _ := parseGlob(args[0]) u, ok := c.Walk(w).Get().(client.Chan) if !ok { fatalf("not a channel") } if err := u.Close(); err != nil { fatalf("close error: %v", err) } }
// circuit mk@leave /X1234/hola/listy func mkonleave(x *cli.Context) { defer func() { if r := recover(); r != nil { fatalf("error, likely due to missing server or misspelled anchor: %v", r) } }() c := dial(x) args := x.Args() if len(args) != 1 { fatalf("mk@leave needs an anchor argument") } w, _ := parseGlob(args[0]) _, err := c.Walk(w).MakeOnLeave() if err != nil { fatalf("mk@leave error: %s", err) } }
func suicide(x *cli.Context) { defer func() { if r := recover(); r != nil { fatalf("error, likely due to missing server or misspelled anchor: %v", r) } }() c := dial(x) args := x.Args() if len(args) != 1 { fatalf("suicide needs one server anchor argument") } w, _ := parseGlob(args[0]) u, ok := c.Walk(w).Get().(client.Server) if !ok { fatalf("not a server") } u.Suicide() }
func nunset(x *cli.Context) { defer func() { if r := recover(); r != nil { fatalf("error, likely due to missing server or misspelled anchor: %v", r) } }() c := dial(x) args := x.Args() if len(args) != 2 { fatalf("unset needs an anchor and a resource name arguments") } w, _ := parseGlob(args[0]) switch u := c.Walk(w).Get().(type) { case client.Nameserver: u.Unset(args[1]) default: fatalf("not a nameserver element") } }
func sgnl(x *cli.Context) { defer func() { if r := recover(); r != nil { fatalf("error, likely due to missing server or misspelled anchor: %v", r) } }() c := dial(x) args := x.Args() if len(args) != 2 { fatalf("signal needs an anchor and a signal name arguments") } w, _ := parseGlob(args[0]) u, ok := c.Walk(w).Get().(client.Proc) if !ok { fatalf("not a process") } if err := u.Signal(args[1]); err != nil { fatalf("signal error: %v", err) } }
func stdout(x *cli.Context) { defer func() { if r := recover(); r != nil { fatalf("error, likely due to missing server or misspelled anchor: %v", r) } }() c := dial(x) args := x.Args() if len(args) != 1 { fatalf("stdout needs one anchor argument") } w, _ := parseGlob(args[0]) u, ok := c.Walk(w).Get().(interface { Stdout() io.ReadCloser }) if !ok { fatalf("not a process or a container") } io.Copy(os.Stdout, u.Stdout()) }
func stderr(x *cli.Context) { defer func() { if r := recover(); r != nil { fatalf("error, likely due to missing server or misspelled anchor: %v", r) } }() c := dial(x) args := x.Args() if len(args) != 1 { fatalf("stderr needs one anchor argument") } w, _ := parseGlob(args[0]) u, ok := c.Walk(w).Get().(client.Proc) if !ok { fatalf("not a process") } io.Copy(os.Stdout, u.Stderr()) // if _, err := io.Copy(os.Stdout, u.Stderr()); err != nil { // fatalf("transmission error: %v", err) // } }
// circuit mkchan /X1234/hola/charlie 0 func mkchan(x *cli.Context) { defer func() { if r := recover(); r != nil { fatalf("error, likely due to missing server or misspelled anchor: %v", r) } }() c := dial(x) args := x.Args() if len(args) != 2 { fatalf("mkchan needs an anchor and a capacity arguments") } w, _ := parseGlob(args[0]) a := c.Walk(w) n, err := strconv.Atoi(args[1]) if err != nil || n < 0 { fatalf("second argument to mkchan must be a non-negative integral capacity") } if _, err = a.MakeChan(n); err != nil { fatalf("mkchan error: %s", err) } }
func mkdns(x *cli.Context) { defer func() { if r := recover(); r != nil { fatalf("error, likely due to missing server or misspelled anchor: %v", r) } }() c := dial(x) args := x.Args() if len(args) < 1 { fatalf("mkdns needs an anchor and an optional address arguments") } var addr string if len(args) == 2 { addr = args[1] } w, _ := parseGlob(args[0]) _, err := c.Walk(w).MakeNameserver(addr) if err != nil { fatalf("mkdns error: %s", err) } }
func wait(x *cli.Context) { defer func() { if r := recover(); r != nil { fatalf("error, likely due to missing server or misspelled anchor: %v", r) } }() c := dial(x) args := x.Args() if len(args) != 1 { fatalf("wait needs one anchor argument") } w, _ := parseGlob(args[0]) u, ok := c.Walk(w).Get().(client.Proc) if !ok { fatalf("not a process") } stat, err := u.Wait() if err != nil { fatalf("wait error: %v", err) } buf, _ := json.MarshalIndent(stat, "", "\t") fmt.Println(string(buf)) }
func stack(x *cli.Context) { defer func() { if r := recover(); r != nil { fatalf("error, likely due to missing server or misspelled anchor: %v", r) } }() c := dial(x) args := x.Args() if len(args) != 1 { fatalf("recv needs one anchor argument") } w, _ := parseGlob(args[0]) switch u := c.Walk(w).Get().(type) { case client.Server: r, err := u.Profile("goroutine") if err != nil { fatalf("error: %v", err) } io.Copy(os.Stdout, r) default: fatalf("not a server") } }