func TestApp_RunAsSubcommandParseFlags(t *testing.T) { var context *cli.Context a := cli.NewApp() a.Commands = []cli.Command{ { Name: "foo", Action: func(c *cli.Context) { context = c }, Flags: []cli.Flag{ cli.StringFlag{ Name: "lang", Value: "english", Usage: "language for the greeting", }, }, Before: func(_ *cli.Context) error { return nil }, }, } a.Run([]string{"", "foo", "--lang", "spanish", "abcd"}) expect(t, context.Args().Get(0), "abcd") expect(t, context.String("lang"), "spanish") }
func cmdProxy(c *cli.Context) { if len(c.Args()) < 1 { Logger.Fatalf("assh: \"proxy\" requires 1 argument. See 'assh proxy --help'.") } conf, err := config.Open() if err != nil { Logger.Fatalf("Cannot open configuration file: %v", err) } // FIXME: handle complete host with json host, err := computeHost(c.Args()[0], c.Int("port"), conf) if err != nil { Logger.Fatalf("Cannot get host '%s': %v", c.Args()[0], err) } w := Logger.Writer() defer w.Close() host.WriteSshConfigTo(w) Logger.Debugf("Saving SSH config") err = conf.SaveSshConfig() if err != nil { Logger.Fatalf("Cannot save SSH config file: %v", err) } Logger.Debugf("Proxying") err = proxy(host, conf) if err != nil { Logger.Fatalf("Proxy error: %v", err) } }
func hookBefore(c *cli.Context) error { if c.Bool("debug") { os.Setenv("ASSH_DEBUG", "1") } initLogging(c.Bool("debug"), c.Bool("verbose")) return nil }
func cmdProxy(c *cli.Context) { if len(c.Args()) < 1 { logrus.Fatalf("assh: \"proxy\" requires 1 argument. See 'assh proxy --help'.") } conf, err := config.Open() if err != nil { logrus.Fatalf("Cannot open configuration file: %v", err) } // FIXME: handle complete host with json host, err := computeHost(c.Args()[0], c.Int("port"), conf) if err != nil { logrus.Fatalf("Cannot get host '%s': %v", c.Args()[0], err) } err = proxy(host, conf) if err != nil { logrus.Fatalf("Proxy error: %v", err) } }
func hookBefore(c *cli.Context) error { initLogging(c.Bool("debug"), c.Bool("verbose")) return nil }