Esempio n. 1
0
func echo_command(cfg *watch.Config, action func(*watch.Config)) cli.Command {
	return cli.Command{
		Name:      "echo",
		Usage:     "echo the full filepath",
		ArgsUsage: "DIR",
		Action: func(c *cli.Context) {

			args := c.Args()

			bail := func() {
				cli.ShowSubcommandHelp(c)
				os.Exit(1)
			}

			if !args.Present() {
				bail()
			}

			cfg.Actions = []watch.Action{
				&watch.EchoAction{},
			}
			cfg.Dir = args.First()
			action(cfg)
		},
	}
}
Esempio n. 2
0
func setup_action(cfg *watch.Config, c *cli.Context) {
	sparanoia := c.GlobalString("paranoia")
	switch sparanoia {
	case "off":
		cfg.Paranoia = watch.NoParanoia
	case "basic":
		cfg.Paranoia = watch.BasicParanoia
	case "extra":
		cfg.Paranoia = watch.ExtraParanoia
	default:
		fmt.Fprintln(os.Stderr, "Invalid choice of paranoia=", c)
		cli.ShowSubcommandHelp(c)
		os.Exit(1)
	}
}
Esempio n. 3
0
func http_post_command(cfg *watch.Config, action func(*watch.Config)) cli.Command {
	var pa watch.PostAction
	//	var http_headers cli.StringSlice
	return cli.Command{
		Name:  "post",
		Usage: "post the file somewhere",
		Flags: []cli.Flag{
			// cli.StringSliceFlag{
			// 	Name:  "header",
			// 	Value: &http_headers,
			// 	Usage: "Set extra http headers, format is KEY:VAL",
			// },
			cli.StringFlag{
				Name:        "mime",
				Destination: &pa.Mime,
				Usage:       "Force the mime type on the post",
			},
			cli.StringFlag{
				Name:        "uname",
				Destination: &pa.BasicAuthUsername,
				Usage:       "Triggers use of HTTP basic auth (See RFC 2617, Section 2.) with the provided username",
			},
			cli.StringFlag{
				Name:        "pass",
				Destination: &pa.BasicAuthPwd,
				Usage:       "Set the password for HTTP basic auth.",
			},
		},
		ArgsUsage: "URL DIR",
		Action: func(c *cli.Context) {

			args := c.Args()

			bail := func() {
				cli.ShowSubcommandHelp(c)
				os.Exit(1)
			}

			if !args.Present() {
				bail()
			}
			arg := 0

			next := func() string {
				val := args.Get(arg)
				arg++
				if val == "" {
					bail()
				}
				return val
			}

			pa.To = next()

			cfg.Actions = []watch.Action{
				&pa,
			}
			cfg.Dir = next()
			action(cfg)
		},
	}
}