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

Extend config for external commands #2536

Merged
merged 5 commits into from
Mar 8, 2024
Merged

Extend config for external commands #2536

merged 5 commits into from
Mar 8, 2024

Conversation

eikek
Copy link
Owner

@eikek eikek commented Mar 8, 2024

Allows to configure external commands and provide different arguments based on runtime values, like language. It extends the current config of a command to allow a arg-mappings section. An example for ocrmypdf:

ocrmypdf = {
  enabled = true
  command = {
    program = "ocrmypdf"
### new arg-mappings
    arg-mappings = {
      "mylang" = {
        value = "{{lang}}"
        mappings = [
          {
            matches = "deu"
            args = [ "-l", "deu", "--pdf-renderer", "sandwich" ]
          },
          {
            matches = ".*"
            args = [ "-l", "{{lang}}" ]
          }
        ]
      }
    }
#### end new arg-mappings
    args = [
      ### will be replaced with corresponding args from "mylang" mapping
      "{{mylang}}", 
      "--skip-text",
      "--deskew",
      "-j", "1",
      "{{infile}}",
      "{{outfile}}"
    ]
    timeout = "5 minutes"
  }
  working-dir = ${java.io.tmpdir}"/docspell-convert"
}

The whole section will be first processed to replace all {{…}} patterns with corresponding values. Then arg-mappings will be looked at and the first match (value == matches) in its mappings array is used to replace its name in the arguments to the command.

@eikek eikek force-pushed the config-cmd branch 3 times, most recently from a227c17 to 1b77be4 Compare March 8, 2024 20:13
@eikek eikek marked this pull request as ready for review March 8, 2024 20:33
@eikek eikek added this to the Docspell 0.42.0 milestone Mar 8, 2024
@eikek eikek marked this pull request as draft March 8, 2024 20:33
@eikek eikek marked this pull request as ready for review March 8, 2024 20:34
@eikek eikek merged commit 8269a73 into master Mar 8, 2024
4 of 5 checks passed
@eikek eikek deleted the config-cmd branch March 8, 2024 20:34
madduck pushed a commit to madduck/docspell that referenced this pull request May 14, 2024
Allows to configure external commands and provide different arguments
based on runtime values, like language. It extends the current config
of a command to allow a `arg-mappings` section. An example for
ocrmypdf:

```conf
ocrmypdf = {
  enabled = true
  command = {
    program = "ocrmypdf"
### new arg-mappings
    arg-mappings = {
      "mylang" = {
        value = "{{lang}}"
        mappings = [
          {
            matches = "deu"
            args = [ "-l", "deu", "--pdf-renderer", "sandwich" ]
          },
          {
            matches = ".*"
            args = [ "-l", "{{lang}}" ]
          }
        ]
      }
    }
#### end new arg-mappings
    args = [
      ### will be replaced with corresponding args from "mylang" mapping
      "{{mylang}}", 
      "--skip-text",
      "--deskew",
      "-j", "1",
      "{{infile}}",
      "{{outfile}}"
    ]
    timeout = "5 minutes"
  }
  working-dir = ${java.io.tmpdir}"/docspell-convert"
}
```

The whole section will be first processed to replace all `{{…}}`
patterns with corresponding values. Then `arg-mappings` will be looked
at and the first match (value == matches) in its `mappings` array is
used to replace its name in the arguments to the command.
@eikek eikek added feature joex affects the joex component labels May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature joex affects the joex component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant