Implement promptCustom in cli and use it for init command.
This commit is contained in:
parent
9b67f424e6
commit
a111d5f3b9
2 changed files with 25 additions and 25 deletions
|
|
@ -35,18 +35,6 @@ else:
|
||||||
proc GetVersionExA*(VersionInformation: var OSVERSIONINFO): WINBOOL{.stdcall,
|
proc GetVersionExA*(VersionInformation: var OSVERSIONINFO): WINBOOL{.stdcall,
|
||||||
dynlib: "kernel32", importc: "GetVersionExA".}
|
dynlib: "kernel32", importc: "GetVersionExA".}
|
||||||
|
|
||||||
proc promptCustom(question, default: string): string =
|
|
||||||
if default == "":
|
|
||||||
stdout.write(question, ": ")
|
|
||||||
let user = stdin.readLine()
|
|
||||||
if user.len == 0: return promptCustom(question, default)
|
|
||||||
else: return user
|
|
||||||
else:
|
|
||||||
stdout.write(question, " [", default, "]: ")
|
|
||||||
let user = stdin.readLine()
|
|
||||||
if user == "": return default
|
|
||||||
else: return user
|
|
||||||
|
|
||||||
proc refresh(options: Options) =
|
proc refresh(options: Options) =
|
||||||
## Downloads the package list from the specified URL.
|
## Downloads the package list from the specified URL.
|
||||||
##
|
##
|
||||||
|
|
@ -804,9 +792,10 @@ proc dump(options: Options) =
|
||||||
proc init(options: Options) =
|
proc init(options: Options) =
|
||||||
var nimbleFile: string = ""
|
var nimbleFile: string = ""
|
||||||
|
|
||||||
echo("In order to initialise a new Nimble package, I will need to ask you\n" &
|
display("Info:",
|
||||||
|
"In order to initialise a new Nimble package, I will need to ask you\n" &
|
||||||
"some questions. Default values are shown in square brackets, press\n" &
|
"some questions. Default values are shown in square brackets, press\n" &
|
||||||
"enter to use them.")
|
"enter to use them.", priority = HighPriority)
|
||||||
|
|
||||||
# Ask for package name.
|
# Ask for package name.
|
||||||
if options.action.projName != "":
|
if options.action.projName != "":
|
||||||
|
|
@ -814,7 +803,7 @@ proc init(options: Options) =
|
||||||
nimbleFile = pkgName.changeFileExt("nimble")
|
nimbleFile = pkgName.changeFileExt("nimble")
|
||||||
else:
|
else:
|
||||||
var pkgName = os.getCurrentDir().splitPath.tail.toValidPackageName()
|
var pkgName = os.getCurrentDir().splitPath.tail.toValidPackageName()
|
||||||
pkgName = promptCustom("Enter package name", pkgName)
|
pkgName = promptCustom("Package name?", pkgName)
|
||||||
nimbleFile = pkgName.changeFileExt("nimble")
|
nimbleFile = pkgName.changeFileExt("nimble")
|
||||||
|
|
||||||
validatePackageName(nimbleFile.changeFileExt(""))
|
validatePackageName(nimbleFile.changeFileExt(""))
|
||||||
|
|
@ -823,7 +812,7 @@ proc init(options: Options) =
|
||||||
raise newException(NimbleError, "Nimble file already exists.")
|
raise newException(NimbleError, "Nimble file already exists.")
|
||||||
|
|
||||||
# Ask for package version.
|
# Ask for package version.
|
||||||
let pkgVersion = promptCustom("Enter initial version of package", "0.1.0")
|
let pkgVersion = promptCustom("Initial version of package?", "0.1.0")
|
||||||
validateVersion(pkgVersion)
|
validateVersion(pkgVersion)
|
||||||
|
|
||||||
# Ask for package author
|
# Ask for package author
|
||||||
|
|
@ -836,25 +825,20 @@ proc init(options: Options) =
|
||||||
let (name, exitCode) = doCmdEx("hg config ui.username")
|
let (name, exitCode) = doCmdEx("hg config ui.username")
|
||||||
if exitCode == QuitSuccess and name.len > 0:
|
if exitCode == QuitSuccess and name.len > 0:
|
||||||
defaultAuthor = name.strip()
|
defaultAuthor = name.strip()
|
||||||
let pkgAuthor = promptCustom("Enter your name", defaultAuthor)
|
let pkgAuthor = promptCustom("Your name?", defaultAuthor)
|
||||||
|
|
||||||
# Ask for description
|
# Ask for description
|
||||||
let pkgDesc = promptCustom("Enter package description", "")
|
let pkgDesc = promptCustom("Package description?", "")
|
||||||
|
|
||||||
# Ask for license
|
# Ask for license
|
||||||
# TODO: Provide selection of licenses, or select random default license.
|
# TODO: Provide selection of licenses, or select random default license.
|
||||||
let pkgLicense = promptCustom("Enter package license", "MIT")
|
let pkgLicense = promptCustom("Package license?", "MIT")
|
||||||
|
|
||||||
# Ask for Nim dependency
|
# Ask for Nim dependency
|
||||||
let nimDepDef = getNimrodVersion()
|
let nimDepDef = getNimrodVersion()
|
||||||
let pkgNimDep = promptCustom("Enter lowest supported Nim version", $nimDepDef)
|
let pkgNimDep = promptCustom("Lowest supported Nim version?", $nimDepDef)
|
||||||
validateVersion(pkgNimDep)
|
validateVersion(pkgNimDep)
|
||||||
|
|
||||||
# Now generate the .nimble file.
|
|
||||||
if existsFile(os.getCurrentDir() / nimbleFile):
|
|
||||||
raise newException(NimbleError,
|
|
||||||
"Looks like a Nimble file has already been created.")
|
|
||||||
|
|
||||||
var outFile: File
|
var outFile: File
|
||||||
if open(f = outFile, filename = nimbleFile, mode = fmWrite):
|
if open(f = outFile, filename = nimbleFile, mode = fmWrite):
|
||||||
outFile.writeLine """# Package
|
outFile.writeLine """# Package
|
||||||
|
|
@ -874,6 +858,8 @@ requires "nim >= $#"
|
||||||
raise newException(NimbleError, "Unable to open file " & nimbleFile &
|
raise newException(NimbleError, "Unable to open file " & nimbleFile &
|
||||||
" for writing: " & osErrorMsg(osLastError()))
|
" for writing: " & osErrorMsg(osLastError()))
|
||||||
|
|
||||||
|
display("Success:", "Nimble file created successfully", Success, HighPriority)
|
||||||
|
|
||||||
proc uninstall(options: Options) =
|
proc uninstall(options: Options) =
|
||||||
if options.action.packages.len == 0:
|
if options.action.packages.len == 0:
|
||||||
raise newException(NimbleError,
|
raise newException(NimbleError,
|
||||||
|
|
|
||||||
|
|
@ -128,6 +128,20 @@ proc prompt*(forcePrompts: ForcePrompt, question: string): bool =
|
||||||
else:
|
else:
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
proc promptCustom*(question, default: string): string =
|
||||||
|
if default == "":
|
||||||
|
display("Prompt:", question, Warning, HighPriority)
|
||||||
|
displayCategory("Answer:", Warning, HighPriority)
|
||||||
|
let user = stdin.readLine()
|
||||||
|
if user.len == 0: return promptCustom(question, default)
|
||||||
|
else: return user
|
||||||
|
else:
|
||||||
|
display("Prompt:", question & " [" & default & "]", Warning, HighPriority)
|
||||||
|
displayCategory("Answer:", Warning, HighPriority)
|
||||||
|
let user = stdin.readLine()
|
||||||
|
if user == "": return default
|
||||||
|
else: return user
|
||||||
|
|
||||||
proc setVerbosity*(level: Priority) =
|
proc setVerbosity*(level: Priority) =
|
||||||
globalCLI.level = level
|
globalCLI.level = level
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue