-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #185 from solver-it-sro/running-autogram-in-CLI-mode
Running autogram in cli mode
- Loading branch information
Showing
39 changed files
with
1,001 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/main/java/digital/slovensko/autogram/core/AppStarter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package digital.slovensko.autogram.core; | ||
|
||
import digital.slovensko.autogram.ui.cli.CliApp; | ||
import digital.slovensko.autogram.ui.gui.GUIApp; | ||
import javafx.application.Application; | ||
import org.apache.commons.cli.*; | ||
|
||
import java.io.PrintWriter; | ||
|
||
public class AppStarter { | ||
private static final Options options = new Options(). | ||
addOptionGroup(new OptionGroup(). | ||
addOption(new Option(null, "url", true, "Start in GUI mode with API server listening on given port and protocol (HTTP/HTTPS). Application starts minimised when is not empty.")). | ||
addOption(new Option("c", "cli", false, "Run application in CLI mode.")) | ||
). | ||
addOption("h", "help", false, "Print this command line help."). | ||
addOption("u", "usage", false, "Print usage examples."). | ||
addOption("s", "source", true, "Source file or directory of files to sign."). | ||
addOption("t", "target", true, "Target file or directory for signed files. Type (file/directory) must match the source."). | ||
addOption("f", "force", false, "Overwrite existing file(s)."). | ||
addOption(null, "pdfa", false, "Check PDF/A compliance before signing."). | ||
addOption(null, "parents", false, "Create all parent directories for target if needed."). | ||
addOption("d", "driver", true, "PCKS driver for signing. Supported drivers: eid, secure_store, monet, gemalto."); | ||
|
||
public static void start(String[] args) { | ||
try { | ||
CommandLine cmd = new DefaultParser().parse(options, args); | ||
|
||
if (cmd.hasOption("h")) { | ||
printHelp(); | ||
} else if (cmd.hasOption("u")) { | ||
printUsage(); | ||
} else if (cmd.hasOption("c")) { | ||
CliApp.start(cmd); | ||
} else { | ||
Application.launch(GUIApp.class, args); | ||
} | ||
} catch (ParseException e) { | ||
System.err.println("Unable to parse program args"); | ||
System.err.println(e); | ||
} | ||
} | ||
|
||
public static void printHelp() { | ||
final HelpFormatter formatter = new HelpFormatter(); | ||
final String syntax = "autogram"; | ||
final String footer = """ | ||
In CLI mode, signed files are saved with the same name as the source file, but with the suffix "_signed" if no target is specified. If the source is a directory, the target must also be a directory. If the source is a file, the target must also be a file. If the source is a driectory and no target is specified, a target directory is created with the same name as the source directory, but with the suffix "_signed". | ||
If no target is specified and generated target name already exists, number is added to the target's name suffix if --force is not enabled. For example, if the source is "file.pdf" and the target is not specified, the target will be "file_signed.pdf". If the target already exists, the target will be "file_signed (1).pdf". If that target already exists, the target will be "file_signed (2).pdf", and so on. | ||
If --force is enabled, the target will be overwritten if it already exists. | ||
If target is specified with missing parent directories, they are created onyl if --parents is enabled. Otherwise, the signing fails. For example, if the source is "file.pdf" and the target is "target/file_signed.pdf", the target directory "target" must exist. If it does not exist, the signing fails. If --parents is enabled, the target directory "target" is created if it does not exist. | ||
"""; | ||
|
||
formatter.printHelp(80, syntax, "", options, footer, true); | ||
} | ||
|
||
public static void printUsage() { | ||
final HelpFormatter formatter = new HelpFormatter(); | ||
final String syntax = """ | ||
autogram [options] | ||
autogram --url=http://localhost:32700 | ||
autogram --cli [options] | ||
autogram --cli -s target/directory-example/file-example.pdf -t target/output-example/out-example.pdf | ||
autogram --cli -s target/directory-example -t target/output-example -f | ||
autogram --cli -s target/directory-example -t target/non-existent-dir/output-example --parents | ||
autogram --cli -s target/directory-example/file-example.pdf -pdfa | ||
autogram --cli -s target/directory-example/file-example.pdf -d eid | ||
"""; | ||
final PrintWriter pw = new PrintWriter(System.out); | ||
formatter.printUsage(pw, 80, syntax); | ||
pw.flush(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.