From c1c61d8ae5a8ec69560fbf0adf1fbc5d86fa2aab Mon Sep 17 00:00:00 2001 From: ee7 <45465154+ee7@users.noreply.github.com> Date: Sat, 6 Aug 2022 18:57:01 +0200 Subject: [PATCH] cli, completion: compress large strings --- configlet.nimble | 11 ++++++----- src/cli.nim | 10 +++++----- src/completion/completion.nim | 5 +++-- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/configlet.nimble b/configlet.nimble index 3946ba1b..2d2826f2 100644 --- a/configlet.nimble +++ b/configlet.nimble @@ -19,10 +19,11 @@ bin = @["configlet"] # Dependencies requires "nim >= 1.6.6" -requires "cligen#b962cf8bc0be847cbc1b4f77952775de765e9689" # 1.5.19 (2021-09-13) -requires "jsony#2a2cc4331720b7695c8b66529dbfea6952727e7b" # 1.1.3 (2022-01-03) -requires "parsetoml#9cdeb3f65fd10302da157db8a8bac5c42f055249" # 0.6.0 (2021-06-07) -requires "uuids#8cb8720b567c6bcb261bd1c0f7491bdb5209ad06" # 0.1.11 (2021-01-15) +requires "cligen#b962cf8bc0be847cbc1b4f77952775de765e9689" # 1.5.19 (2021-09-13) +requires "jsony#2a2cc4331720b7695c8b66529dbfea6952727e7b" # 1.1.3 (2022-01-03) +requires "parsetoml#9cdeb3f65fd10302da157db8a8bac5c42f055249" # 0.6.0 (2021-06-07) +requires "supersnappy#e4df8cb5468dd96fc5a4764028e20c8a3942f16a" # 2.1.3 (2022-06-12) +requires "uuids#8cb8720b567c6bcb261bd1c0f7491bdb5209ad06" # 0.1.11 (2021-01-15) # To make Nimble use the pinned `isaac` version, we must pin `isaac` after `uuids` # (which has `isaac` as a dependency). # Nimble still clones the latest `isaac` tag if there is no tag-versioned one @@ -30,7 +31,7 @@ requires "uuids#8cb8720b567c6bcb261bd1c0f7491bdb5209ad06" # 0.1.11 (2021-01- # building, but (due to writing it later) the pinned version takes precedence. # Nimble will support lock files in the future, which should provide more robust # version pinning. -requires "isaac#45a5cbbd54ff59ba3ed94242620c818b9aad1b5b" # 0.1.3 (2017-11-16) +requires "isaac#45a5cbbd54ff59ba3ed94242620c818b9aad1b5b" # 0.1.3 (2017-11-16) task test, "Runs the test suite": exec "nim r ./tests/all_tests.nim" diff --git a/src/cli.nim b/src/cli.nim index fbb24151..34541686 100644 --- a/src/cli.nim +++ b/src/cli.nim @@ -1,5 +1,5 @@ import std/[os, parseutils, strformat, strutils, terminal] -import pkg/cligen/parseopt3 +import pkg/[cligen/parseopt3, supersnappy] type ActionKind* = enum @@ -295,9 +295,9 @@ func genHelpText: string = setLen(result, result.len - 1) proc showHelp(exitCode: range[0..255] = 0) = - const helpText = genHelpText() + const helpText = genHelpText().compress() let f = if exitCode == 0: stdout else: stderr - f.writeLine helpText + f.writeLine helpText.uncompress() if f == stdout: f.flushFile() quit(exitCode) @@ -415,8 +415,8 @@ proc parseOption(kind: CmdLineKind, key: string, val: string): Opt = user's cache directory - there is no longer an option to configure the location. Performing an offline sync now requires only one option (--offline), but you must first run a `configlet sync` command without --offline at least once on - your machine.""".unindent() - stderr.writeLine msg + your machine.""".unindent().compress() + stderr.writeLine msg.uncompress() showError(&"invalid option: {formatOpt(kind, key)}") proc parseVal[T: enum](kind: CmdLineKind, key: string, val: string): T = diff --git a/src/completion/completion.nim b/src/completion/completion.nim index ec5058b4..a322786e 100644 --- a/src/completion/completion.nim +++ b/src/completion/completion.nim @@ -1,12 +1,13 @@ import std/[os, strformat] +import pkg/supersnappy import ../cli proc readCompletions: array[Shell, string] = const repoRootDir = currentSourcePath().parentDir().parentDir().parentDir() const completionsDir = repoRootDir / "completions" for shell in sBash .. result.high: - result[shell] = staticRead(completionsDir / &"configlet.{shell}") + result[shell] = staticRead(completionsDir / &"configlet.{shell}").compress() proc completion*(shellKind: Shell) = const completions = readCompletions() - stdout.write completions[shellKind] + stdout.write completions[shellKind].uncompress()