'Init' feature initial implementation
Added the init() proc to babel.nim as well as a new TActionType and supporting code in doAction. The idea is that if you have a project already created in a directory, this will create a .babel file with sane defaults. I also updated the help text describe the 'init' feature as with the other babel commands.
This commit is contained in:
parent
07d4fd2253
commit
d5d28c8fcf
1 changed files with 52 additions and 2 deletions
|
|
@ -21,8 +21,8 @@ type
|
||||||
babelData: PJsonNode ## Babeldata.json
|
babelData: PJsonNode ## Babeldata.json
|
||||||
|
|
||||||
TActionType = enum
|
TActionType = enum
|
||||||
ActionNil, ActionUpdate, ActionInstall, ActionSearch, ActionList,
|
ActionNil, ActionUpdate, ActionInit, ActionInstall, ActionSearch,
|
||||||
ActionBuild, ActionPath, ActionUninstall
|
ActionList, ActionBuild, ActionPath, ActionUninstall
|
||||||
|
|
||||||
TAction = object
|
TAction = object
|
||||||
case typ: TActionType
|
case typ: TActionType
|
||||||
|
|
@ -35,6 +35,8 @@ type
|
||||||
packages: seq[TPkgTuple] # Optional only for ActionInstall.
|
packages: seq[TPkgTuple] # Optional only for ActionInstall.
|
||||||
of ActionSearch:
|
of ActionSearch:
|
||||||
search: seq[string] # Search string.
|
search: seq[string] # Search string.
|
||||||
|
of ActionInit:
|
||||||
|
projName: string
|
||||||
|
|
||||||
TForcePrompt = enum
|
TForcePrompt = enum
|
||||||
DontForcePrompt, ForcePromptYes, ForcePromptNo
|
DontForcePrompt, ForcePromptYes, ForcePromptNo
|
||||||
|
|
@ -45,6 +47,7 @@ Usage: babel COMMAND [opts]
|
||||||
|
|
||||||
Commands:
|
Commands:
|
||||||
install [pkgname, ...] Installs a list of packages.
|
install [pkgname, ...] Installs a list of packages.
|
||||||
|
init [pkgname, ...] Initializes a new Babel project
|
||||||
uninstall [pkgname, ...] Uninstalls a list of packages.
|
uninstall [pkgname, ...] Uninstalls a list of packages.
|
||||||
build Builds a package.
|
build Builds a package.
|
||||||
update [url] Updates package list. A package list URL can
|
update [url] Updates package list. A package list URL can
|
||||||
|
|
@ -100,6 +103,9 @@ proc parseCmdLine(): TOptions =
|
||||||
result.action.packages = @[]
|
result.action.packages = @[]
|
||||||
of "build":
|
of "build":
|
||||||
result.action.typ = ActionBuild
|
result.action.typ = ActionBuild
|
||||||
|
of "init":
|
||||||
|
result.action.typ = ActionInit
|
||||||
|
result.action.projName = ""
|
||||||
of "update":
|
of "update":
|
||||||
result.action.typ = ActionUpdate
|
result.action.typ = ActionUpdate
|
||||||
result.action.optionalURL = ""
|
result.action.optionalURL = ""
|
||||||
|
|
@ -128,6 +134,10 @@ proc parseCmdLine(): TOptions =
|
||||||
result.action.optionalURL = key
|
result.action.optionalURL = key
|
||||||
of ActionSearch:
|
of ActionSearch:
|
||||||
result.action.search.add(key)
|
result.action.search.add(key)
|
||||||
|
of ActionInit:
|
||||||
|
if result.action.projName != "":
|
||||||
|
quit("ERROR: MORE THAN ONE ARGUMENT FOR PACKAGE NAME.")
|
||||||
|
result.action.projName = key
|
||||||
of ActionList, ActionBuild:
|
of ActionList, ActionBuild:
|
||||||
writeHelp()
|
writeHelp()
|
||||||
of cmdLongOption, cmdShortOption:
|
of cmdLongOption, cmdShortOption:
|
||||||
|
|
@ -656,6 +666,44 @@ proc listPaths(options: TOptions) =
|
||||||
if errors > 0:
|
if errors > 0:
|
||||||
raise newException(EBabel, "At least one of the specified packages was not found")
|
raise newException(EBabel, "At least one of the specified packages was not found")
|
||||||
|
|
||||||
|
proc init(options: TOptions) =
|
||||||
|
echo("Initializing new Babel project!")
|
||||||
|
var
|
||||||
|
pkgName, fName: string = ""
|
||||||
|
outFile: TFile
|
||||||
|
|
||||||
|
if (options.action.projName != ""):
|
||||||
|
pkgName = options.action.projName
|
||||||
|
fName = pkgName & ".babel"
|
||||||
|
if ( existsFile( os.getCurrentDir() / fName ) ):
|
||||||
|
quit("Already have a babel file.")
|
||||||
|
|
||||||
|
else:
|
||||||
|
echo("Enter a project name for this (blank to use working directory), Ctrl-C to abort:")
|
||||||
|
pkgName = readline(stdin)
|
||||||
|
if (pkgName == ""):
|
||||||
|
pkgName = os.getCurrentDir().splitPath.tail
|
||||||
|
if (pkgName == ""):
|
||||||
|
raise newException(EBabel, "Could not get default file path.")
|
||||||
|
fName = pkgName & ".babel"
|
||||||
|
|
||||||
|
# Now need to write out .babel file with projName and other details
|
||||||
|
|
||||||
|
if (not existsFile( os.getCurrentDir() / fName) and open(f=outFile, filename = fName, mode = fmWrite) ):
|
||||||
|
outFile.write("[Package]\n")
|
||||||
|
outFile.write("name = \"" & pkgName & "\"\n")
|
||||||
|
outFile.write("version = \"0.01\"\n")
|
||||||
|
outFile.write("author = \"Anonymous\"\n")
|
||||||
|
outFile.write("description = \"New Babel project for Nimrod\"\n")
|
||||||
|
outFile.write("license = \"BSD\"\n")
|
||||||
|
outFile.write("\n")
|
||||||
|
outFile.write("[Deps]\n")
|
||||||
|
outFile.write("Requires: \"nimrod >= 0.9.4\"\n")
|
||||||
|
close(outFile)
|
||||||
|
|
||||||
|
else:
|
||||||
|
quit("Unable to open file " & fName & " for writing. Check if file exists?")
|
||||||
|
|
||||||
proc uninstall(options: TOptions) =
|
proc uninstall(options: TOptions) =
|
||||||
var pkgsToDelete: seq[TPackageInfo] = @[]
|
var pkgsToDelete: seq[TPackageInfo] = @[]
|
||||||
# Do some verification.
|
# Do some verification.
|
||||||
|
|
@ -730,6 +778,8 @@ proc doAction(options: TOptions) =
|
||||||
listPaths(options)
|
listPaths(options)
|
||||||
of ActionBuild:
|
of ActionBuild:
|
||||||
build(options)
|
build(options)
|
||||||
|
of ActionInit:
|
||||||
|
init(options)
|
||||||
of ActionNil:
|
of ActionNil:
|
||||||
assert false
|
assert false
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue