Mercurial > cgi-bin > hgweb.cgi > ImagePrep
changeset 4:5234e4500d45
Command-line arguments (only partially tested).
author | David Barts <n5jrn@me.com> |
---|---|
date | Fri, 17 Jul 2020 14:51:41 -0700 |
parents | 09dcd475d1bf |
children | 884f1415a330 |
files | build.xml src/name/blackcap/imageprep/Files.kt src/name/blackcap/imageprep/Main.kt src/name/blackcap/imageprep/Settings.kt |
diffstat | 4 files changed, 72 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/build.xml Fri Jul 17 11:48:07 2020 -0700 +++ b/build.xml Fri Jul 17 14:51:41 2020 -0700 @@ -66,6 +66,9 @@ <target name="classpath"> <path id="compile.classpath"> <pathelement location="${src.home}"/> + <fileset dir="${lib.home}"> + <include name="*.jar"/> + </fileset> </path> </target> @@ -110,6 +113,7 @@ <attribute name="Main-Class" value="${app.entry}"/> </manifest> <!-- <zipgroupfileset dir="${lib.home}" includes="*.jar"/> --> + <zipgroupfileset dir="${lib.home}" includes="*.jar"/> <zipfileset src="${work.jar}"/> <zipfileset dir="${src.home}" includes="**/*.properties,**/*.html"/> </jar>
--- a/src/name/blackcap/imageprep/Files.kt Fri Jul 17 11:48:07 2020 -0700 +++ b/src/name/blackcap/imageprep/Files.kt Fri Jul 17 14:51:41 2020 -0700 @@ -40,7 +40,7 @@ /* file names */ -private val SHORTNAME = "imageprep" +private val SHORTNAME = Application.MYNAME.toLowerCase() private val LONGNAME = "name.blackcap." + SHORTNAME private val HOME = System.getenv("HOME") val PF_DIR = when (OS.type) {
--- a/src/name/blackcap/imageprep/Main.kt Fri Jul 17 11:48:07 2020 -0700 +++ b/src/name/blackcap/imageprep/Main.kt Fri Jul 17 14:51:41 2020 -0700 @@ -3,9 +3,17 @@ */ package name.blackcap.imageprep -import javax.swing.UIManager +import java.io.File import java.util.logging.Level import java.util.logging.Logger +import javax.swing.UIManager +import name.blackcap.kcli.CommandLine +import name.blackcap.kcli.InvalidArgumentException +import name.blackcap.kcli.Option +import name.blackcap.kcli.PromptingParser +import org.apache.commons.cli.HelpFormatter +import org.apache.commons.cli.Options +import org.apache.commons.cli.ParseException object Application { /* name we call ourselves */ @@ -30,7 +38,60 @@ if (OS.type == OS.MAC) { System.setProperty("apple.laf.useScreenMenuBar", "true") } + + if (Settings.outputToInputDir) + Settings.outputTo = System.getProperty("user.dir") + val options = Options().apply { + addOption(Option<Unit>("?", "help", false, "Print this help message.")) + addOption(Option<Int>("m", "maxdim", true, "Maximum dimension (default: ${Settings.maxDimension})").apply { + default = Settings.maxDimension + interpolater = { + val ret = try { it.toInt() } catch (e: NumberFormatException) { -1 } + if (ret < 1) + throw InvalidArgumentException("Dimension must be a positive integer.") + Settings.maxDimension = ret + ret + } + }) + addOption(Option<File>("o", "output", true, "Output directory (default: ${Settings.outputTo})").apply { + default = File(Settings.outputTo) + interpolater = { + val ret = File(it) + if (!ret.exists()) + throw InvalidArgumentException("'${it}' does not exist") + if (!ret.isDirectory()) + throw InvalidArgumentException("'${it}' is not a directory") + Settings.outputTo = ret.canonicalPath + ret + } + }) + addOption(Option<Int>("q", "quality", true, "JPEG quality for output (0-100, default ${Settings.outputQuality})").apply { + default = Settings.outputQuality + interpolater = { + val ret = try { it.toInt() } catch (e: NumberFormatException) { -1 } + if (ret < 0 || ret > 100) + throw InvalidArgumentException("Quality must be an integer from 0 to 100, inclusive.") + Settings.outputQuality = ret + ret + } + }) + } + val cmdLine: CommandLine? = try { + PromptingParser().parse(options, args) + } catch (e: ParseException) { + System.err.println("${Application.MYNAME}: syntax error - ${e.message}") + System.exit(2) + null + } + if (cmdLine!!.hasOption("help")) { + val usage = Application.MYNAME + " [--maxdim=integer] [--output=directory] [--quality=integer] file [...]" + HelpFormatter().printHelp(usage, options, false); + System.exit(0); + } + inSwingThread { Application.initialize() + for (fileName in cmdLine!!.args) + RotateDialog.makeDialog(File(fileName)) } }
--- a/src/name/blackcap/imageprep/Settings.kt Fri Jul 17 11:48:07 2020 -0700 +++ b/src/name/blackcap/imageprep/Settings.kt Fri Jul 17 14:51:41 2020 -0700 @@ -10,11 +10,11 @@ object Settings { private val homeDir = System.getProperty("user.home") - val maxDimension = _PROPS.getProperty("maxDimension").toInt() - val outputQuality = _PROPS.getProperty("outputQuality").toInt() - val outputSuffix = _PROPS.getProperty("outputSuffix") - val outputTo = tilde(_PROPS.getProperty("outputTo")) - val outputToInputDir = strToBool(_PROPS.getProperty("outputToInputDir")) + var maxDimension = _PROPS.getProperty("maxDimension").toInt() + var outputQuality = _PROPS.getProperty("outputQuality").toInt() + var outputSuffix = _PROPS.getProperty("outputSuffix") + var outputTo = tilde(_PROPS.getProperty("outputTo")) + var outputToInputDir = strToBool(_PROPS.getProperty("outputToInputDir")) private fun tilde(s: String?): String { if (s.isNullOrEmpty())