示例#1
0
文件: app.go 项目: logdns/conoha-iso
func (app *ConoHaIso) download(flags []cli.Flag) cli.Command {

	flags = append(flags, cli.StringFlag{
		Name:  "url, i",
		Value: "",
		Usage: "ISO file url.",
	})

	cmd := cli.Command{
		Name:  "download",
		Usage: "Download ISO file from the FTP/HTTP server.",
		Flags: flags,
		After: app.afterAction,
		Before: func(c *cli.Context) error {
			if c.String("url") == "" {
				return errors.New("ISO file url is required.")
			}
			return nil
		},
		Action: func(c *cli.Context) {

			ident, err := app.auth(c)
			if err != nil {
				app.lastError = err
				return
			}

			var compute *command.Compute
			compute = command.NewCompute(ident)

			if err = compute.Download(c.String("url")); err != nil {
				app.lastError = err
				return
			}

			log.Info("Download request was accepted.")
		},
	}
	return cmd
}