Example #1
0
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")
}
Example #2
0
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)
	}
}
Example #3
0
func hookBefore(c *cli.Context) error {
	if c.Bool("debug") {
		os.Setenv("ASSH_DEBUG", "1")
	}
	initLogging(c.Bool("debug"), c.Bool("verbose"))
	return nil
}
Example #4
0
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)
	}
}
Example #5
0
func hookBefore(c *cli.Context) error {
	initLogging(c.Bool("debug"), c.Bool("verbose"))
	return nil
}