'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
|
||||
|
||||
TActionType = enum
|
||||
ActionNil, ActionUpdate, ActionInstall, ActionSearch, ActionList,
|
||||
ActionBuild, ActionPath, ActionUninstall
|
||||
ActionNil, ActionUpdate, ActionInit, ActionInstall, ActionSearch,
|
||||
ActionList, ActionBuild, ActionPath, ActionUninstall
|
||||
|
||||
TAction = object
|
||||
case typ: TActionType
|
||||
|
|
@ -35,6 +35,8 @@ type
|
|||
packages: seq[TPkgTuple] # Optional only for ActionInstall.
|
||||
of ActionSearch:
|
||||
search: seq[string] # Search string.
|
||||
of ActionInit:
|
||||
projName: string
|
||||
|
||||
TForcePrompt = enum
|
||||
DontForcePrompt, ForcePromptYes, ForcePromptNo
|
||||
|
|
@ -45,6 +47,7 @@ Usage: babel COMMAND [opts]
|
|||
|
||||
Commands:
|
||||
install [pkgname, ...] Installs a list of packages.
|
||||
init [pkgname, ...] Initializes a new Babel project
|
||||
uninstall [pkgname, ...] Uninstalls a list of packages.
|
||||
build Builds a package.
|
||||
update [url] Updates package list. A package list URL can
|
||||
|
|
@ -100,6 +103,9 @@ proc parseCmdLine(): TOptions =
|
|||
result.action.packages = @[]
|
||||
of "build":
|
||||
result.action.typ = ActionBuild
|
||||
of "init":
|
||||
result.action.typ = ActionInit
|
||||
result.action.projName = ""
|
||||
of "update":
|
||||
result.action.typ = ActionUpdate
|
||||
result.action.optionalURL = ""
|
||||
|
|
@ -128,6 +134,10 @@ proc parseCmdLine(): TOptions =
|
|||
result.action.optionalURL = key
|
||||
of ActionSearch:
|
||||
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:
|
||||
writeHelp()
|
||||
of cmdLongOption, cmdShortOption:
|
||||
|
|
@ -656,6 +666,44 @@ proc listPaths(options: TOptions) =
|
|||
if errors > 0:
|
||||
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) =
|
||||
var pkgsToDelete: seq[TPackageInfo] = @[]
|
||||
# Do some verification.
|
||||
|
|
@ -730,6 +778,8 @@ proc doAction(options: TOptions) =
|
|||
listPaths(options)
|
||||
of ActionBuild:
|
||||
build(options)
|
||||
of ActionInit:
|
||||
init(options)
|
||||
of ActionNil:
|
||||
assert false
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue