Skip to content
Merged
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
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ find / "Journal-..-..-2024"
# Or just search for all files with 2024 in the filename
find / ".*2024.*"
# If you want to search ignore character casing, you can do that as follows:
find / "(?!i)case_insensitive_search"
find / "(?i)case_insensitive_search"

# Find files with either "Work" or "Personal" tag
find --tag="Work" --tag="Personal"
Expand Down Expand Up @@ -227,6 +227,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
7 changes: 6 additions & 1 deletion shell/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func findCmd(ctx *ShellCtxt) *ishell.Cmd {
case 0:
start = ctx.path
default:
c.Err(errors.New("missing arguments; usage find [options] [dir] [regexp]"))
flagSet.Usage()
return
}

Expand All @@ -87,6 +87,11 @@ func findCmd(ctx *ShellCtxt) *ishell.Cmd {

filetree.WalkTree(startNode, filetree.FileTreeVistor{
Visit: func(node *model.Node, path []string) bool {
// Skip items in trash
if node.Document != nil && node.Document.Parent == "trash" {
return false
}

// Filter by starred status if flag was set
if starredFilterEnabled && node.Document != nil {
if node.Document.Starred != starred {
Expand Down
40 changes: 30 additions & 10 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"
flag "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 := flag.NewFlagSet("get", flag.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