Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add config root support #205

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions cmd/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,19 @@ func put(cmd *cobra.Command, args []string) (err error) {
Size: contentsInfo.Size(),
}

commitInfo := files.NewCommitInfo(dst)
commitInfo.Mode.Tag = "overwrite"
uploadArg := files.NewUploadArg(dst)
uploadArg.Mode.Tag = "overwrite"

// The Dropbox API only accepts timestamps in UTC with second precision.
ts := time.Now().UTC().Round(time.Second)
commitInfo.ClientModified = &ts
uploadArg.ClientModified = &ts

dbx := files.New(config)
if contentsInfo.Size() > singleShotUploadSizeCutoff {
return uploadChunked(dbx, progressbar, commitInfo, contentsInfo.Size(), workers, chunkSize, debug)
return uploadChunked(dbx, progressbar, &uploadArg.CommitInfo, contentsInfo.Size(), workers, chunkSize, debug)
}

if _, err = dbx.Upload(commitInfo, progressbar); err != nil {
if _, err = dbx.Upload(uploadArg, progressbar); err != nil {
return
}

Expand Down
12 changes: 11 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,16 @@ func initDbx(cmd *cobra.Command, args []string) (err error) {
URLGenerator: nil,
}

return
root, err := cmd.Flags().GetString("root")
if err != nil {
return fmt.Errorf("root parameter: %w", err)
}

if root != "" {
config = config.WithRoot(root)
}

return nil
}

// RootCmd represents the base command when called without any subcommands
Expand All @@ -232,6 +241,7 @@ func Execute() {
func init() {
RootCmd.PersistentFlags().BoolP("verbose", "v", false, "Enable verbose logging")
RootCmd.PersistentFlags().String("as-member", "", "Member ID to perform action as")
RootCmd.PersistentFlags().String("root", "", "Use a different root directory")
// This flag should only be used for testing. Marked hidden so it doesn't clutter usage etc.
RootCmd.PersistentFlags().String("domain", "", "Override default Dropbox domain, useful for testing")
RootCmd.PersistentFlags().MarkHidden("domain")
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ module github.com/dropbox/dbxcli
go 1.11

require (
github.com/dropbox/dropbox-sdk-go-unofficial/v6 v6.0.1
github.com/dropbox/dropbox-sdk-go-unofficial/v6 v6.0.5
github.com/dustin/go-humanize v1.0.0
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/ioprogress v0.0.0-20180201004757-6a23b12fa88e
github.com/spf13/cobra v0.0.4-0.20190109003409-7547e83b2d85
github.com/spf13/pflag v1.0.3 // indirect
golang.org/x/net v0.0.0-20201224014010-6772e930b67b
golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5
golang.org/x/net v0.18.0
golang.org/x/oauth2 v0.14.0
)
Loading