From 5b7b061465d77f4798816d7b813a4fe888fa87ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ois=C3=ADn=20Mac=20Fheara=C3=AD?= Date: Sat, 27 Jul 2019 17:55:59 +0100 Subject: [PATCH] Remove escaping of author name and package description in `nimble init`, since it replaces characters used in many names and languages with escape sequences. Slightly refactor the code for determining author name, to make it easier to add other version control systems in future (right now it's just git and hg). Also, add some binary test artifacts to .gitignore so they don't accidentally get committed in future. --- .gitignore | 11 ++++++++++- src/nimble.nim | 22 +++++++++++----------- src/nimblepkg/init.nim | 2 +- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 5744c47..76ef2d8 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,14 @@ nimcache/ /nimble /tests/nimscript/nimscript /tests/issue27/issue27 +src/nimblepkg/cli +src/nimblepkg/packageinfo +src/nimblepkg/packageparser +src/nimblepkg/reversedeps +src/nimblepkg/version +tests/nimble-test/ +tests/packageStructure/validBinary/y +tests/testCommand/testsFail/tests/t2 # Windows executables *.exe @@ -19,4 +27,5 @@ nimcache/ # VCC compiler and linker artifacts *.ilk -*.pdb \ No newline at end of file +*.pdb + diff --git a/src/nimble.nim b/src/nimble.nim index 69086be..f62795b 100644 --- a/src/nimble.nim +++ b/src/nimble.nim @@ -724,20 +724,20 @@ proc init(options: Options) = display("Using", "$# for new package name" % [pkgName.escape()], priority = HighPriority) - # Ask for package author + # Determine author by running an external command + proc getAuthorWithCmd(cmd: string): string = + let (name, exitCode) = doCmdEx(cmd) + if exitCode == QuitSuccess and name.len > 0: + result = name.strip() + display("Using", "$# for new package author" % [result], + priority = HighPriority) + + # Determine package author via git/hg or asking proc getAuthor(): string = if findExe("git") != "": - let (name, exitCode) = doCmdEx("git config --global user.name") - if exitCode == QuitSuccess and name.len > 0: - result = name.strip() - display("Using", "$# for new package author" % [result.escape()], - priority = HighPriority) + result = getAuthorWithCmd("git config --global user.name") elif findExe("hg") != "": - let (name, exitCode) = doCmdEx("hg config ui.username") - if exitCode == QuitSuccess and name.len > 0: - result = name.strip() - display("Using", "$# for new package author" % [result.escape()], - priority = HighPriority) + result = getAuthorWithCmd("hg config ui.username") if result.len == 0: result = promptCustom(options, "Your name?", "Anonymous") let pkgAuthor = getAuthor() diff --git a/src/nimblepkg/init.nim b/src/nimblepkg/init.nim index 085c616..2378b5f 100644 --- a/src/nimblepkg/init.nim +++ b/src/nimblepkg/init.nim @@ -175,7 +175,7 @@ $# requires "nim >= $#" """ % [ - info.pkgVersion.escape(), info.pkgAuthor.escape(), info.pkgDesc.escape(), + info.pkgVersion.escape(), info.pkgAuthor, info.pkgDesc.escape(), info.pkgLicense.escape(), info.pkgSrcDir.escape(), nimbleFileOptions, pkgBackend, info.pkgNimDep ]