aboutsummaryrefslogtreecommitdiff
path: root/src/libmain/shared.hh
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2009-11-24 12:26:25 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2009-11-24 12:26:25 +0000
commit9b8fda796b620a5476e8a50edcc29a3462667fc3 (patch)
treefa546a5b5a0b08c01a7bdc9ee50e69d7bfd87165 /src/libmain/shared.hh
parent80220155523fb21c938d595e96597f6511aa7bd0 (diff)
* Templatise getIntArg / string2Int.
Diffstat (limited to 'src/libmain/shared.hh')
-rw-r--r--src/libmain/shared.hh16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/libmain/shared.hh b/src/libmain/shared.hh
index c432dc5f7..f70f6893b 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();