diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/foreground/FlowProgressForegroundService.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/foreground/FlowProgressForegroundService.kt index d64db10bda..17bd38777f 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/foreground/FlowProgressForegroundService.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/foreground/FlowProgressForegroundService.kt @@ -91,13 +91,17 @@ abstract class FlowProgressForegroundService : Service() { protected abstract fun cancelAll() /** Called for every emission before [render]; use to update derived subclass state. */ - protected open fun onEmission(value: T) {} + protected open fun onEmission(value: T) { + // No-op by default: only subclasses that keep derived state need this hook. + } /** Only consulted for the [refreshMs] clock loop; skip re-renders when nothing is moving. */ protected open fun needsClockRefresh(value: T): Boolean = true /** One-time setup once the watch loop starts (e.g. a benchmark). */ - protected open fun onStarted() {} + protected open fun onStarted() { + // No-op by default: only subclasses with one-time setup (e.g. a benchmark) override this. + } /** How to draw the progress bar of the card. */ sealed interface Bar { diff --git a/cli/src/main/kotlin/com/vitorpamplona/amethyst/cli/Main.kt b/cli/src/main/kotlin/com/vitorpamplona/amethyst/cli/Main.kt index 4a755bd79e..541d1cb45f 100644 --- a/cli/src/main/kotlin/com/vitorpamplona/amethyst/cli/Main.kt +++ b/cli/src/main/kotlin/com/vitorpamplona/amethyst/cli/Main.kt @@ -164,8 +164,11 @@ class AwaitTimeout( */ private val STRICT_ACCOUNT_VERBS = setOf("init", "create", "login", "logoff", "whoami") +private const val HELP_FLAG = "--help" +private const val HELP_FLAG_SHORT = "-h" + private suspend fun dispatch(argv: Array): Int { - if (argv.firstOrNull() == "--help" || argv.firstOrNull() == "-h") { + if (argv.firstOrNull() == HELP_FLAG || argv.firstOrNull() == HELP_FLAG_SHORT) { printUsage() return 0 } @@ -203,9 +206,9 @@ private suspend fun dispatch(argv: Array): Int { // becomes a plain leading --help, so `amy notes post "hi" --help` prints // usage instead of publishing, and no command can forget to honor it. // (`--` still lets you pass the literal text: `amy notes post -- --help`.) - val helpIdx = tail.indexOfFirst { it == "--" || it == "--help" || it == "-h" } + val helpIdx = tail.indexOfFirst { it == "--" || it == HELP_FLAG || it == HELP_FLAG_SHORT } if (helpIdx >= 0 && tail[helpIdx] != "--") { - tail = arrayOf("--help") + tail = arrayOf(HELP_FLAG) } // `use` operates on `/current` directly and must work even diff --git a/cli/src/main/kotlin/com/vitorpamplona/amethyst/cli/commands/DmCommands.kt b/cli/src/main/kotlin/com/vitorpamplona/amethyst/cli/commands/DmCommands.kt index a9a0ecde1e..2049fe927b 100644 --- a/cli/src/main/kotlin/com/vitorpamplona/amethyst/cli/commands/DmCommands.kt +++ b/cli/src/main/kotlin/com/vitorpamplona/amethyst/cli/commands/DmCommands.kt @@ -137,7 +137,7 @@ object DmCommands { ): Int { val args = Args(rest) val allowFallback = args.bool("allow-fallback") - args.rejectUnknown("file", "server", "mime-type", "key", "nonce", "hash", "original-hash", "size", "dim", "blurhash") + args.rejectUnknown("file", "server", FLAG_MIME_TYPE, "key", "nonce", "hash", "original-hash", "size", "dim", "blurhash") val recipientInput = args.positionalOrNull(0) ?: return Output.error("bad_args", USAGE_SEND_FILE) Context.open(dataDir).use { ctx -> @@ -186,7 +186,7 @@ object DmCommands { Output.error("upload_failed", "Blossom server $server returned no URL") return null } - val mimeType = args.flag("mime-type") ?: uploaded.metadata.mimeType + val mimeType = args.flag(FLAG_MIME_TYPE) ?: uploaded.metadata.mimeType val dimension = uploaded.metadata.width?.let { w -> uploaded.metadata.height?.let { h -> @@ -247,7 +247,7 @@ object DmCommands { Output.error("bad_args", "--nonce must be hex (got ${nonceHex.length} chars)") return null } - val mimeType = args.flag("mime-type") + val mimeType = args.flag(FLAG_MIME_TYPE) val hash = args.flag("hash") val originalHash = args.flag("original-hash") val size = args.flag("size")?.toIntOrNull() @@ -282,6 +282,8 @@ object DmCommands { return result to emptyMap() } + private const val FLAG_MIME_TYPE = "mime-type" + private const val USAGE_SEND_FILE: String = "dm send-file [--file PATH --server URL | URL --key HEX --nonce HEX] " + "[--mime-type M] [--hash HEX] [--original-hash HEX] [--size N] [--dim WxH] [--blurhash S] [--allow-fallback]"