about summary refs log tree commit diff
path: root/src/libmain
diff options
context:
space:
mode:
Diffstat (limited to 'src/libmain')
-rw-r--r--src/libmain/shared.cc18
-rw-r--r--src/libmain/shared.hh16
2 files changed, 15 insertions, 19 deletions
diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc
index 10ccb2985f74..0f7a89814b6d 100644
--- a/src/libmain/shared.cc
+++ b/src/libmain/shared.cc
@@ -87,18 +87,6 @@ static void setLogType(string lt)
 }
 
 
-unsigned long long getIntArg(const string & opt,
-    Strings::iterator & i, const Strings::iterator & end)
-{
-    ++i;
-    if (i == end) throw UsageError(format("`%1%' requires an argument") % opt);
-    long long n;
-    if (!string2Int(*i, n) || n < 0)
-        throw UsageError(format("`%1%' requires a non-negative integer") % opt);
-    return n;
-}
-
-
 void initDerivationsHelpers();
 
 
@@ -195,7 +183,7 @@ static void initAndRun(int argc, char * * argv)
     for (Strings::iterator i = args.begin(); i != args.end(); ++i) {
         string arg = *i;
         if (string(arg, 0, 4) == "-at-") ;
-        else if (arg.length() > 2 && arg[0] == '-' && arg[1] != '-') {
+        else if (arg.length() > 2 && arg[0] == '-' && arg[1] != '-' && !isdigit(arg[1])) {
             for (unsigned int j = 1; j < arg.length(); j++)
                 if (isalpha(arg[j]))
                     remaining.push_back((string) "-" + arg[j]);
@@ -239,11 +227,11 @@ static void initAndRun(int argc, char * * argv)
         else if (arg == "--fallback")
             tryFallback = true;
         else if (arg == "--max-jobs" || arg == "-j")
-            maxBuildJobs = getIntArg(arg, i, args.end());
+            maxBuildJobs = getIntArg<unsigned int>(arg, i, args.end());
         else if (arg == "--readonly-mode")
             readOnlyMode = true;
         else if (arg == "--max-silent-time")
-            maxSilentTime = getIntArg(arg, i, args.end());
+            maxSilentTime = getIntArg<unsigned int>(arg, i, args.end());
         else if (arg == "--no-build-hook")
             useBuildHook = false;
         else if (arg == "--show-trace")
diff --git a/src/libmain/shared.hh b/src/libmain/shared.hh
index c432dc5f7b56..f70f6893b4bd 100644
--- a/src/libmain/shared.hh
+++ b/src/libmain/shared.hh
@@ -22,22 +22,30 @@ extern std::string programId;
 
 namespace nix {
 
+MakeError(UsageError, nix::Error);
+
 /* Ugh.  No better place to put this. */
 Path makeRootName(const Path & gcRoot, int & counter);
 void printGCWarning();
 
 void printMissing(const PathSet & paths);
 
-unsigned long long getIntArg(const string & opt,
-    Strings::iterator & i, const Strings::iterator & end);
+template<class N> N getIntArg(const string & opt,
+    Strings::iterator & i, const Strings::iterator & end)
+{
+    ++i;
+    if (i == end) throw UsageError(format("`%1%' requires an argument") % opt);
+    N n;
+    if (!string2Int(*i, n))
+        throw UsageError(format("`%1%' requires an integer argument") % opt);
+    return n;
+}
 
 /* Whether we're running setuid. */
 extern bool setuidMode;
 
 extern volatile ::sig_atomic_t blockInt;
 
-MakeError(UsageError, nix::Error);
-
 struct RemoveTempRoots 
 {
     ~RemoveTempRoots();