func (c *pingCmd) run(args []string) error { if len(args) > 0 { return errArgs } config, err := flex.LoadConfig() if err != nil { return err } remoteHack(config) // NewClient will ping the server to test the connection before returning. _, err = flex.NewClient(config) return err }
func (c *listCmd) run(args []string) error { if len(args) > 0 { return errArgs } config, err := flex.LoadConfig() if err != nil { return err } // NewClient will ping the server to test the connection before returning. d, err := flex.NewClient(config) if err != nil { return err } l, err := d.List() if err != nil { return err } fmt.Println(l) return err }
func (c *byNameCmd) run(args []string) error { name := "foo" // todo - come up with a random name as juju does if len(args) > 1 { return errArgs } if len(args) == 1 { name = args[0] } config, err := flex.LoadConfig() if err != nil { return err } d, err := flex.NewClient(config) if err != nil { return err } data, err := c.do(d, name) fmt.Println(data) return err }
func (c *attachCmd) run(args []string) error { name := "foo" if len(args) > 1 { return errArgs } if len(args) == 1 { name = args[0] } config, err := flex.LoadConfig() if err != nil { return err } // NewClient will ping the server to test the connection before returning. d, err := flex.NewClient(config) if err != nil { return err } // TODO - random value in place of 5 :) secret := "5" l, err := d.Attach(name, "/bin/bash", secret) if err != nil { return err } cfd := syscall.Stdout if terminal.IsTerminal(cfd) { oldttystate, err := terminal.MakeRaw(cfd) if err != nil { return err } defer terminal.Restore(cfd, oldttystate) } // open a connection to l and connect stdin/stdout to it // connect conn, err := net.Dial("tcp", l) if err != nil { return err } _, err = conn.Write([]byte(secret)) if err != nil { return err } go func() { _, err := io.Copy(conn, os.Stdin) if err != nil { fmt.Println("Stdin read error: %s", err.Error()) return } }() _, err = io.Copy(os.Stdout, conn) if err != nil { fmt.Println("Connection read error: %s", err.Error()) return err } return nil }