Bug 152192 - Support output filepath in CLI convert
Summary: Support output filepath in CLI convert
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
7.4.2.3 release
Hardware: All All
: medium enhancement
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Commandline
  Show dependency treegraph
 
Reported: 2022-11-23 22:13 UTC by assk
Modified: 2022-12-03 09:57 UTC (History)
0 users

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description assk 2022-11-23 22:13:48 UTC
Description:
Command line interface convert using --convert-to does not support specifying an output filepath. It supports specifying an output folder --outdir.

This makes using LibreOffice for workflow conversion in foreach loops using input and output filepaths cumbersome. You need extra code to circumvent for instance, if you want to rename your output file. This means after conversion you have to write code to search for the converted file and then rename it, not really having full control of the workflow.

Adding support for output filepaths would be great!

Actual Results:
At the moment, you can only set an output folder.

Expected Results:
Possibility to set output filepath in LibreOffice CLI.
There should be a check to make sure the extension of output filepath is identical to set --convert-to extension.
There should be a check to make sure that both output filepath and output folder is not set at the same time.


Reproducible: Always


User Profile Reset: No

Additional Info:
Thanks for making it possible to use LibreOffice in CLI mode to convert files.
Comment 1 Mike Kaganski 2022-11-24 03:53:57 UTC
Given that the --convert-to is a switch, which enables conversion mode for *any number* of following input files, and its --outdir matches that - it looks not easy to come with a logical CLI to specify per-file output name... any suggestion?
Comment 2 assk 2022-11-24 11:33:32 UTC
Hi, I forgot to mention, if I use scalc.exe instead of soffice.exe for spreadsheets, then it is possible to give an input filepath meaning it won't bulk process any folder. The option does not have a parameter i.e. --inputfilepath, you simply put the filepath anywhere as parameter. My suggestion is to supplement this with a new --outputfilepath and explicitly add --inputfilepath so the above mentioned filepath is not "floating around".

I see two different ways of using an enhanced --convert-to

1.
"<path to scalc.exe>" --headless --convert-to <extension> --inputdir <dir> --outputdir <dir> *xlsx

2.
"<path to scalc.exe>" --headless --convert-to <extension> --inputfilepath <filepath> --outputfilepath <filepath>

Checks
* outputfilepath extension should be checked against designated --convert-to extension. If so, throw exception.
* check to make sure that both --outputfilepath and --outputdir is not set at the same time. If so, throw exception.
* check to make sure that if --outputfilepath or --outputdir is set, then --inputfilepath or --outputdir is required. If not so, throw exception.

I looked at the source code, and I am not experienced enough to make any pull request on this.
Comment 3 Mike Kaganski 2022-11-24 12:23:04 UTC
Adding an optional argument that would provide an output name for an immediately preceding filename (only working in conversion mode) would likely be the best option. It could be either relative name (then --outdir would still be reasonable), or absolute (then --outdir would be irrelevant, simply ignored without a diagnostic).

A check of extension is not needed. Why? LibreOffice itself relies on file type detection based on content; it's not uncommon to have CSVs named differently (TSV, DAT, TXT, even XLS); and so why not trust user who may have their reasons? You never provided a rationale for the suggested check.

A code pointer: start at desktop/source/app/cmdlineargs.cxx [1]

[1] https://opengrok.libreoffice.org/xref/core/desktop/source/app/cmdlineargs.cxx?r=ebd697df#284
Comment 4 assk 2022-11-25 13:38:49 UTC
Your proposed solution will work, as far as I can see at the moment.

You are right. It is not necessary to check output filepath extension and --convert-to extension.