From 9a67b0866463308984b78572324954436c0ec6ca Mon Sep 17 00:00:00 2001 From: singularperturbation Date: Tue, 2 Sep 2014 17:59:45 -0500 Subject: [PATCH] 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 --- src/babel.nim | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/babel.nim b/src/babel.nim index 9e21819..10db107 100644 --- a/src/babel.nim +++ b/src/babel.nim @@ -47,7 +47,7 @@ Usage: babel COMMAND [opts] Commands: 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. build Builds a package. update [url] Updates package list. A package list URL can @@ -136,7 +136,7 @@ proc parseCmdLine(): TOptions = result.action.search.add(key) of ActionInit: 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 of ActionList, ActionBuild: writeHelp() @@ -668,7 +668,7 @@ proc listPaths(options: TOptions) = proc init(options: TOptions) = echo("Initializing new Babel project!") - var + var pkgName, fName: string = "" outFile: TFile @@ -676,8 +676,7 @@ proc init(options: TOptions) = pkgName = options.action.projName fName = pkgName & ".babel" if ( existsFile( os.getCurrentDir() / fName ) ): - quit("Already have a babel file.") - + raise newException(EBabel, "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) @@ -690,19 +689,19 @@ proc init(options: TOptions) = # 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") + outFile.writeln("[Package]") + outFile.writeln("name = \"" & pkgName & "\"") + outFile.writeln("version = \"0.01\"") + outFile.writeln("author = \"Anonymous\"") + outFile.writeln("description = \"New Babel project for Nimrod\"") + outFile.writeln("license = \"BSD\"") + outFile.writeln("") + outFile.writeln("[Deps]") + outFile.writeln("Requires: \"nimrod >= 0.9.4\"") close(outFile) 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) = var pkgsToDelete: seq[TPackageInfo] = @[]