Reuse -y to mean accept defaults for init command for #288 (#437)

* Reuse -y to mean accept defaults for init command

* Change cli.promptCustom to accept a ForcePrompt value and delegate prompting responsiblity to it

* Add prompt for different license selection

* Remove extra spaces in category in promptCustom and promptList

* Fix bug that always returned MIT

* Add LGPL3 to array of licenses

* Change to not prompt at all for package name

* Change to not prompt for author if acquired from vcs and moved before prompting for version

* Reduce excess indenting

* Create tools.writeContents to contain file writting functionality and use it to write the nimble file

* Create package src directory and add it to the nimble file

* Write an initial source file

* Create directory and files needed for testing

* Add package created message and change priority of nimble file creation

* Rearrange args for promptCustom and add another promptCustom function that doesn't accept ForcePrompt

* Add package type prompt, remove writeContents proc, rename initial test file, provide alternate initial file contents based on type, and other minor improvements
This commit is contained in:
antizealot1337 2017-12-21 18:11:02 -05:00 committed by Dominik Picheta
commit 4cc1d44bdd
4 changed files with 185 additions and 52 deletions

View file

@ -146,19 +146,43 @@ 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
proc promptCustom*(forcePrompts: ForcePrompt, question, default: string): string =
case forcePrompts:
of forcePromptYes:
display("Prompt:", question & " -> [forced " & default & "]", Warning,
HighPriority)
return default
else:
display("Prompt:", question & " [" & default & "]", Warning, HighPriority)
if default == "":
display("Prompt:", question, Warning, HighPriority)
displayCategory("Answer:", Warning, HighPriority)
let user = stdin.readLine()
if user.len == 0: return promptCustom(forcePrompts, 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 promptCustom*(question, default: string): string =
return promptCustom(dontForcePrompt, question, default)
proc promptList*(forcePrompts: ForcePrompt, question: string, args: openarray[string]): string =
case forcePrompts:
of forcePromptYes:
result = args[0]
display("Prompt:", question & " -> [forced " & result & "]", Warning,
HighPriority)
else:
display("Prompt:", question & " [" & join(args, "/") & "]", Warning, HighPriority)
displayCategory("Answer:", Warning, HighPriority)
let user = stdin.readLine()
if user == "": return default
else: return user
result = stdin.readLine()
for arg in args:
if arg.cmpIgnoreCase(result) == 0:
return arg
return promptList(forcePrompts, question, args)
proc setVerbosity*(level: Priority) =
globalCLI.level = level

View file

@ -194,6 +194,20 @@ proc prompt*(options: Options, question: string): bool =
## forcePrompts has a value different than dontForcePrompt.
return prompt(options.forcePrompts, question)
proc promptCustom*(options: Options, question, default: string): string =
## Asks an interactive question and returns the result.
##
## The proc will return "default" without asking the user if the global
## forcePrompts is forcePromptYes.
return promptCustom(options.forcePrompts, question, default)
proc promptList*(options: Options, question: string, args: openarray[string]): string =
## Asks an interactive question and returns the result.
##
## The proc will return one of the provided args. If not prompting the first
## options is selected.
return promptList(options.forcePrompts, question, args)
proc renameBabelToNimble(options: Options) {.deprecated.} =
let babelDir = getHomeDir() / ".babel"
let nimbleDir = getHomeDir() / ".nimble"
@ -384,4 +398,4 @@ proc briefClone*(options: Options): Options =
newOptions.config = options.config
newOptions.nimbleData = options.nimbleData
newOptions.pkgInfoCache = options.pkgInfoCache
return newOptions
return newOptions

View file

@ -80,10 +80,10 @@ proc changeRoot*(origRoot, newRoot, path: string): string =
## path: /home/dom/bar/blah/2/foo.txt
## Return value -> /home/test/bar/blah/2/foo.txt
## The additional check of `path.samePaths(origRoot)` is necessary to prevent
## a regression, where by ending the `srcDir` defintion in a nimble file in a
## The additional check of `path.samePaths(origRoot)` is necessary to prevent
## a regression, where by ending the `srcDir` defintion in a nimble file in a
## trailing separator would cause the `path.startsWith(origRoot)` evaluation to
## fail because of the value of `origRoot` would be longer than `path` due to
## fail because of the value of `origRoot` would be longer than `path` due to
## the trailing separator. This would cause this method to throw during package
## installation.
if path.startsWith(origRoot) or path.samePaths(origRoot):
@ -157,4 +157,4 @@ proc getNimbleTempDir*(): string =
importc: "GetCurrentProcessId".}
result.add($GetCurrentProcessId())
else:
result.add($getpid())
result.add($getpid())