示例#1
0
文件: chan.go 项目: prodigeni/circuit
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)
	// }
}
示例#2
0
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)
	}
}
示例#3
0
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))
}
示例#4
0
文件: proc.go 项目: prodigeni/circuit
// 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)
	}
}
示例#5
0
文件: std.go 项目: herokai/circuit
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)
	}
}
示例#6
0
// 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")
	}
}
示例#7
0
文件: server.go 项目: keryoo/circuit
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")
	}
}
示例#8
0
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")
	}
}
示例#9
0
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()
}
示例#10
0
文件: ls.go 项目: hanjin8307/circuit
// 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"))
}
示例#11
0
文件: chan.go 项目: prodigeni/circuit
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)
	}
}
示例#12
0
// 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)
	}
}
示例#13
0
文件: server.go 项目: keryoo/circuit
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()
}
示例#14
0
文件: dns.go 项目: keryoo/circuit
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")
	}
}
示例#15
0
文件: proc.go 项目: prodigeni/circuit
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)
	}
}
示例#16
0
文件: std.go 项目: herokai/circuit
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())
}
示例#17
0
文件: std.go 项目: hanjin8307/circuit
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)
	// }
}
示例#18
0
文件: chan.go 项目: prodigeni/circuit
// 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)
	}
}
示例#19
0
文件: dns.go 项目: keryoo/circuit
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)
	}
}
示例#20
0
文件: proc.go 项目: prodigeni/circuit
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))
}
示例#21
0
文件: server.go 项目: keryoo/circuit
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")
	}
}