Skip to content
Closed
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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,20 @@ mput (-src sourcfolder) /Papers

Use `get path_to_file` to download a file from the cloud to your local computer.

### Download flags

- `--id`: Interpret the argument as a document ID instead of a path. This is useful when you have the document ID from the `find` command's JSON output.

Examples:

```bash
# Download by path
get /Books/MyBook

# Download by document ID (find document ID using the stat command or --json flag)
get --id abc123-def456-789
```

## Recursively download directories and files

Use `mget path_to_dir` to recursively download all the files in that directory.
Expand Down
2 changes: 1 addition & 1 deletion api/sync15/blobdoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (d *BlobDoc) LineWithSchema(schema string) string {
// Mirror updates the document to be the same as the remote
func (d *BlobDoc) Mirror(e *Entry, r RemoteStorage) error {
d.Entry = *e
entryIndex, err := r.GetReader(e.Hash, e.DocumentID)
entryIndex, err := r.GetReader(e.Hash, addExt(e.DocumentID, archive.DocSchemaExt))
if err != nil {
return err
}
Expand Down
42 changes: 31 additions & 11 deletions shell/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,57 @@ import (
"fmt"

"github.com/abiosoft/ishell"
"github.com/juruen/rmapi/model"
"github.com/juruen/rmapi/util"
"github.com/ogier/pflag"
)

func getCmd(ctx *ShellCtxt) *ishell.Cmd {
longHelp := `Usage: get <remote_file>`
longHelp := `Usage: get [--id] <path|id>`

return &ishell.Cmd{
Name: "get",
Help: "copy remote file to local",
Completer: createEntryCompleter(ctx),
LongHelp: longHelp,
Func: func(c *ishell.Context) {
if checkHelp(longHelp, c.Args, c) {
flagSet := pflag.NewFlagSet("get", pflag.ContinueOnError)
var byId bool
flagSet.BoolVar(&byId, "id", false, "interpret argument as document ID instead of path")
if !processFlagSet(flagSet, longHelp, c.Args, c) {
return
}
args := flagSet.Args()

if len(c.Args) == 0 {
c.Err(errors.New("missing source file"))
if len(args) == 0 {
c.Err(errors.New("missing source file or id"))
return
}

srcName := c.Args[0]
srcArg := args[0]
var node *model.Node
var err error

node, err := ctx.api.Filetree().NodeByPath(srcName, ctx.node)
if byId {
node = ctx.api.Filetree().NodeById(srcArg)
if node == nil {
c.Err(errors.New("document with given ID doesn't exist"))
return
}
} else {
node, err = ctx.api.Filetree().NodeByPath(srcArg, ctx.node)
if err != nil {
c.Err(errors.New("file doesn't exist"))
return
}
}

if err != nil || node.IsDirectory() {
c.Err(errors.New("file doesn't exist"))
if node.IsDirectory() {
c.Err(errors.New("cannot download a directory"))
return
}

c.Println(fmt.Sprintf("downloading: [%s]...", srcName))
c.Println(fmt.Sprintf("downloading: [%s]...", node.Name()))

err = ctx.api.FetchDocument(node.Document.ID, fmt.Sprintf("%s.%s", node.Name(), util.RMDOC))

Expand All @@ -44,7 +64,7 @@ func getCmd(ctx *ShellCtxt) *ishell.Cmd {
return
}

c.Err(errors.New(fmt.Sprintf("Failed to download file %s with %s", srcName, err.Error())))
c.Err(errors.New(fmt.Sprintf("Failed to download file %s with %s", node.Name(), err.Error())))
},
}
}
}
Loading