func (s *ConfigSuite) TestLoadConfig(c *C) { err := ioutil.WriteFile(s.confPath, []byte("test-option: value"), 0644) c.Assert(err, IsNil) cfg, err := flex.LoadConfig() c.Assert(err, IsNil) c.Assert(cfg.TestOption, Equals, "value") }
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 *testCmd) run(args []string) error { if len(args) > 0 { // Command does not take any positional arguments. return errArgs } flex.Logf("Normal message, visible with -v.") flex.Debugf("Debug message, visible with --debug") fmt.Println("Short option (-s):", c.short) fmt.Println("Long option (--long):", c.long) config, err := flex.LoadConfig() if err != nil { return err } fmt.Println("Config option test-option:", config.TestOption) return nil }
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 *daemonCmd) run(args []string) error { if len(args) > 0 { return errArgs } config, err := flex.LoadConfig() if err != nil { return err } config.ListenAddr = c.listenAddr d, err := flex.StartDaemon(config) if err != nil { return err } ch := make(chan os.Signal) signal.Notify(ch, syscall.SIGINT) signal.Notify(ch, syscall.SIGTERM) <-ch return d.Stop() }
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 }
func (s *ConfigSuite) TestReadConfigMissing(c *C) { cfg, err := flex.LoadConfig() c.Assert(err, IsNil) c.Assert(cfg.TestOption, Equals, "") }