# HG changeset patch # User David Barts # Date 1595022701 25200 # Node ID 5234e4500d45ed7dc33fa797c3eeedffca4175ae # Parent 09dcd475d1bf51499deb4d498d851b4234133198 Command-line arguments (only partially tested). diff -r 09dcd475d1bf -r 5234e4500d45 build.xml --- 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 @@ + + + @@ -110,6 +113,7 @@ + diff -r 09dcd475d1bf -r 5234e4500d45 src/name/blackcap/imageprep/Files.kt --- 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) { diff -r 09dcd475d1bf -r 5234e4500d45 src/name/blackcap/imageprep/Main.kt --- 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("?", "help", false, "Print this help message.")) + addOption(Option("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("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("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)) } } diff -r 09dcd475d1bf -r 5234e4500d45 src/name/blackcap/imageprep/Settings.kt --- 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())