Пример #1
0
func main() {
	options := struct {
		Server   string        `goptions:"-s, --server, obligatory, description='Server to connect to'"`
		Password string        `goptions:"-p, --password, description='Don\\'t prompt for password'"`
		Timeout  time.Duration `goptions:"-t, --timeout, description='Connection timeout in seconds'"`
		Help     goptions.Help `goptions:"-h, --help, description='Show this help'"`

		goptions.Verbs
		Execute struct {
			Command string   `goptions:"--command, mutexgroup='input', description='Command to exectute', obligatory"`
			Script  *os.File `goptions:"--script, mutexgroup='input', description='Script to exectute', rdonly"`
		} `goptions:"execute"`
		Delete struct {
			Path  string `goptions:"-n, --name, obligatory, description='Name of the entity to be deleted'"`
			Force bool   `goptions:"-f, --force, description='Force removal'"`
		} `goptions:"delete"`
	}{ // Default values goes here
		Timeout: 10 * time.Second,
	}
	goptions.ParseAndFail(&options)
}
Пример #2
0
func main() {
	opts := &Options{}
	goptions.ParseAndFail(opts)

	// Print version number and exit if the version flag is set
	if opts.Version {
		fmt.Printf("gdrive v%s\n", VersionNumber)
		return
	}

	// Get authorized drive client
	drive, err := gdrive.New(opts.AppPath, opts.Advanced, true)
	if err != nil {
		writeError("An error occurred creating Drive client: %v\n", err)
	}

	switch opts.Verbs {
	case "list":
		args := opts.List
		err = cli.List(drive, args.Query, args.TitleFilter, args.MaxResults, args.SharedStatus, args.NoHeader, args.IncludeDocs, args.SizeInBytes)

	case "info":
		err = cli.Info(drive, opts.Info.FileId, opts.Info.SizeInBytes)

	case "folder":
		args := opts.Folder
		err = cli.Folder(drive, args.Title, args.ParentId, args.Share)

	case "upload":
		args := opts.Upload

		if args.Stdin {
			err = cli.UploadStdin(drive, os.Stdin, args.Title, args.ParentId, args.Share, args.MimeType, args.Convert)
		} else {
			err = cli.Upload(drive, args.File, args.Title, args.ParentId, args.Share, args.MimeType, args.Convert)
		}

	case "download":
		args := opts.Download
		if args.Pop {
			err = cli.DownloadLatest(drive, args.Stdout, args.Format, args.Force)
		} else {
			err = cli.Download(drive, args.FileId, args.Stdout, false, args.Format, args.Force)
		}

	case "delete":
		err = cli.Delete(drive, opts.Delete.FileId)

	case "share":
		err = cli.Share(drive, opts.Share.FileId)

	case "unshare":
		err = cli.Unshare(drive, opts.Unshare.FileId)

	case "url":
		if opts.Url.Download {
			fmt.Println(util.DownloadUrl(opts.Url.FileId))
		} else {
			fmt.Println(util.PreviewUrl(opts.Url.FileId))
		}

	case "quota":
		err = cli.Quota(drive, opts.Quota.SizeInBytes)

	case "empty":
		err = cli.EmptyTrash(drive)

	case "deleteall":
		args := opts.DeleteAll
		err = cli.DeleteAll(drive, args.Query, args.TitleFilter, args.MaxResults, args.IncludeDocs)

	default:
		goptions.PrintHelp()
	}

	if err != nil {
		writeError("%s", err)
	}
}