Move import flow behind subcommand
This commit is contained in:
@@ -53,10 +53,10 @@ Configuration fields:
|
|||||||
|
|
||||||
## Import and archive workflow
|
## Import and archive workflow
|
||||||
|
|
||||||
Run the default command without a subcommand:
|
Run the `import` subcommand:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docspell-cli
|
docspell-cli import
|
||||||
```
|
```
|
||||||
|
|
||||||
The command logs in with `dsc`, scans every configured import directory, and checks each file against Docspell.
|
The command logs in with `dsc`, scans every configured import directory, and checks each file against Docspell.
|
||||||
@@ -76,8 +76,8 @@ If the Docspell item has no folder, `null` is used as the folder name. The corre
|
|||||||
By default, files that do not exist in Docspell stay in place. Enable uploads with either the flag or environment variable:
|
By default, files that do not exist in Docspell stay in place. Enable uploads with either the flag or environment variable:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docspell-cli --upload-missing
|
docspell-cli import --upload-missing
|
||||||
DS_CC_UPLOAD_MISSING=true docspell-cli
|
DS_CC_UPLOAD_MISSING=true docspell-cli import
|
||||||
```
|
```
|
||||||
|
|
||||||
Uploaded files are not archived immediately. They are re-checked on the next run, after Docspell has processed and confirmed them.
|
Uploaded files are not archived immediately. They are re-checked on the next run, after Docspell has processed and confirmed them.
|
||||||
|
|||||||
@@ -38,31 +38,80 @@ type DocspellItem struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
cfg, password := loadConfigAndPassword()
|
if len(os.Args) < 2 {
|
||||||
|
printUsage(os.Stderr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if len(os.Args) > 1 && os.Args[1] == "mount" {
|
switch os.Args[1] {
|
||||||
|
case "import":
|
||||||
|
if isHelpRequest(os.Args[2:]) {
|
||||||
|
runImportCommand(config{}, "", os.Args[2:])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cfg, password := loadConfigAndPassword()
|
||||||
|
runImportCommand(cfg, password, os.Args[2:])
|
||||||
|
case "mount":
|
||||||
|
if isHelpRequest(os.Args[2:]) {
|
||||||
|
_ = runMountCommand(os.Args[2:], config{}, "")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cfg, password := loadConfigAndPassword()
|
||||||
if err := runMountCommand(os.Args[2:], cfg, password); err != nil {
|
if err := runMountCommand(os.Args[2:], cfg, password); err != nil {
|
||||||
fmt.Fprintln(os.Stderr, "mount failed:", err)
|
fmt.Fprintln(os.Stderr, "mount failed:", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
case "get-path":
|
||||||
|
if isHelpRequest(os.Args[2:]) {
|
||||||
|
_ = runGetPathCommand(os.Args[2:], config{}, "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(os.Args) > 1 && os.Args[1] == "get-path" {
|
cfg, password := loadConfigAndPassword()
|
||||||
if err := runGetPathCommand(os.Args[2:], cfg, password); err != nil {
|
if err := runGetPathCommand(os.Args[2:], cfg, password); err != nil {
|
||||||
fmt.Fprintln(os.Stderr, "get-path failed:", err)
|
fmt.Fprintln(os.Stderr, "get-path failed:", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
case "get-url":
|
||||||
|
if isHelpRequest(os.Args[2:]) {
|
||||||
|
_ = runGetURLCommand(os.Args[2:], config{}, "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(os.Args) > 1 && os.Args[1] == "get-url" {
|
cfg, password := loadConfigAndPassword()
|
||||||
if err := runGetURLCommand(os.Args[2:], cfg, password); err != nil {
|
if err := runGetURLCommand(os.Args[2:], cfg, password); err != nil {
|
||||||
fmt.Fprintln(os.Stderr, "get-url failed:", err)
|
fmt.Fprintln(os.Stderr, "get-url failed:", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
return
|
case "-h", "--help", "help":
|
||||||
|
printUsage(os.Stdout)
|
||||||
|
default:
|
||||||
|
fmt.Fprintf(os.Stderr, "unknown command %q\n\n", os.Args[1])
|
||||||
|
printUsage(os.Stderr)
|
||||||
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
runImportCommand(cfg, password, os.Args[1:])
|
func isHelpRequest(args []string) bool {
|
||||||
|
for _, arg := range args {
|
||||||
|
if arg == "-h" || arg == "--help" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func printUsage(out *os.File) {
|
||||||
|
name := filepath.Base(os.Args[0])
|
||||||
|
fmt.Fprintf(out, `Usage:
|
||||||
|
%[1]s <command> [flags]
|
||||||
|
|
||||||
|
Commands:
|
||||||
|
import Scan configured import folders, archive confirmed files, and optionally upload missing files
|
||||||
|
mount Expose Docspell search results as a read-only FUSE filesystem
|
||||||
|
get-path Resolve a Docspell item ID or URL to the local mounted path
|
||||||
|
get-url Resolve a local mounted path, item ID, or item URL to a Docspell web URL
|
||||||
|
|
||||||
|
Run "%[1]s <command> -h" for command-specific help.
|
||||||
|
`, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadConfigAndPassword() (config, string) {
|
func loadConfigAndPassword() (config, string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user