Style changes, fix some bugs, raise exceptions
Did some cleanup to better match style conventions, switched out 'quit' statements in favor of raising 'EBabel' exceptions, used writeln, and other cleanup. See https://github.com/nimrod-code/babel/pull/58
This commit is contained in:
parent
d5d28c8fcf
commit
9a67b08664
1 changed files with 14 additions and 15 deletions
|
|
@ -47,7 +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
|
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
|
||||||
|
|
@ -136,7 +136,7 @@ proc parseCmdLine(): TOptions =
|
||||||
result.action.search.add(key)
|
result.action.search.add(key)
|
||||||
of ActionInit:
|
of ActionInit:
|
||||||
if result.action.projName != "":
|
if result.action.projName != "":
|
||||||
quit("ERROR: MORE THAN ONE ARGUMENT FOR PACKAGE NAME.")
|
raise newException(EBabel, "Can only initialize one package at a time.")
|
||||||
result.action.projName = key
|
result.action.projName = key
|
||||||
of ActionList, ActionBuild:
|
of ActionList, ActionBuild:
|
||||||
writeHelp()
|
writeHelp()
|
||||||
|
|
@ -668,7 +668,7 @@ proc listPaths(options: TOptions) =
|
||||||
|
|
||||||
proc init(options: TOptions) =
|
proc init(options: TOptions) =
|
||||||
echo("Initializing new Babel project!")
|
echo("Initializing new Babel project!")
|
||||||
var
|
var
|
||||||
pkgName, fName: string = ""
|
pkgName, fName: string = ""
|
||||||
outFile: TFile
|
outFile: TFile
|
||||||
|
|
||||||
|
|
@ -676,8 +676,7 @@ proc init(options: TOptions) =
|
||||||
pkgName = options.action.projName
|
pkgName = options.action.projName
|
||||||
fName = pkgName & ".babel"
|
fName = pkgName & ".babel"
|
||||||
if ( existsFile( os.getCurrentDir() / fName ) ):
|
if ( existsFile( os.getCurrentDir() / fName ) ):
|
||||||
quit("Already have a babel file.")
|
raise newException(EBabel, "Already have a babel file.")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
echo("Enter a project name for this (blank to use working directory), Ctrl-C to abort:")
|
echo("Enter a project name for this (blank to use working directory), Ctrl-C to abort:")
|
||||||
pkgName = readline(stdin)
|
pkgName = readline(stdin)
|
||||||
|
|
@ -690,19 +689,19 @@ proc init(options: TOptions) =
|
||||||
# Now need to write out .babel file with projName and other details
|
# 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) ):
|
if (not existsFile( os.getCurrentDir() / fName) and open(f=outFile, filename = fName, mode = fmWrite) ):
|
||||||
outFile.write("[Package]\n")
|
outFile.writeln("[Package]")
|
||||||
outFile.write("name = \"" & pkgName & "\"\n")
|
outFile.writeln("name = \"" & pkgName & "\"")
|
||||||
outFile.write("version = \"0.01\"\n")
|
outFile.writeln("version = \"0.01\"")
|
||||||
outFile.write("author = \"Anonymous\"\n")
|
outFile.writeln("author = \"Anonymous\"")
|
||||||
outFile.write("description = \"New Babel project for Nimrod\"\n")
|
outFile.writeln("description = \"New Babel project for Nimrod\"")
|
||||||
outFile.write("license = \"BSD\"\n")
|
outFile.writeln("license = \"BSD\"")
|
||||||
outFile.write("\n")
|
outFile.writeln("")
|
||||||
outFile.write("[Deps]\n")
|
outFile.writeln("[Deps]")
|
||||||
outFile.write("Requires: \"nimrod >= 0.9.4\"\n")
|
outFile.writeln("Requires: \"nimrod >= 0.9.4\"")
|
||||||
close(outFile)
|
close(outFile)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
quit("Unable to open file " & fName & " for writing. Check if file exists?")
|
raise newException(EBabel, "Unable to open file " & fName & " for writing: " & osErrorMsg())
|
||||||
|
|
||||||
proc uninstall(options: TOptions) =
|
proc uninstall(options: TOptions) =
|
||||||
var pkgsToDelete: seq[TPackageInfo] = @[]
|
var pkgsToDelete: seq[TPackageInfo] = @[]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue