diff --git a/src/nimble.nim b/src/nimble.nim index b236e9b..aab0a97 100644 --- a/src/nimble.nim +++ b/src/nimble.nim @@ -35,18 +35,6 @@ else: proc GetVersionExA*(VersionInformation: var OSVERSIONINFO): WINBOOL{.stdcall, 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) = ## Downloads the package list from the specified URL. ## @@ -804,9 +792,10 @@ proc dump(options: Options) = proc init(options: Options) = 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" & - "enter to use them.") + "enter to use them.", priority = HighPriority) # Ask for package name. if options.action.projName != "": @@ -814,7 +803,7 @@ proc init(options: Options) = nimbleFile = pkgName.changeFileExt("nimble") else: var pkgName = os.getCurrentDir().splitPath.tail.toValidPackageName() - pkgName = promptCustom("Enter package name", pkgName) + pkgName = promptCustom("Package name?", pkgName) nimbleFile = pkgName.changeFileExt("nimble") validatePackageName(nimbleFile.changeFileExt("")) @@ -823,7 +812,7 @@ proc init(options: Options) = raise newException(NimbleError, "Nimble file already exists.") # 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) # Ask for package author @@ -836,25 +825,20 @@ proc init(options: Options) = let (name, exitCode) = doCmdEx("hg config ui.username") if exitCode == QuitSuccess and name.len > 0: defaultAuthor = name.strip() - let pkgAuthor = promptCustom("Enter your name", defaultAuthor) + let pkgAuthor = promptCustom("Your name?", defaultAuthor) # Ask for description - let pkgDesc = promptCustom("Enter package description", "") + let pkgDesc = promptCustom("Package description?", "") # Ask for 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 let nimDepDef = getNimrodVersion() - let pkgNimDep = promptCustom("Enter lowest supported Nim version", $nimDepDef) + let pkgNimDep = promptCustom("Lowest supported Nim version?", $nimDepDef) 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 if open(f = outFile, filename = nimbleFile, mode = fmWrite): outFile.writeLine """# Package @@ -874,6 +858,8 @@ requires "nim >= $#" raise newException(NimbleError, "Unable to open file " & nimbleFile & " for writing: " & osErrorMsg(osLastError())) + display("Success:", "Nimble file created successfully", Success, HighPriority) + proc uninstall(options: Options) = if options.action.packages.len == 0: raise newException(NimbleError, diff --git a/src/nimblepkg/cli.nim b/src/nimblepkg/cli.nim index 3822187..1c616e3 100644 --- a/src/nimblepkg/cli.nim +++ b/src/nimblepkg/cli.nim @@ -128,6 +128,20 @@ proc prompt*(forcePrompts: ForcePrompt, question: string): bool = else: 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) = globalCLI.level = level