From 47e185847e729d49e6aa376e8299fd66ef834a0a Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 13 Aug 2014 03:50:44 +0200 Subject: Refactor option handling --- src/libmain/shared.hh | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'src/libmain/shared.hh') diff --git a/src/libmain/shared.hh b/src/libmain/shared.hh index b29b08bb5..c74e7cbc1 100644 --- a/src/libmain/shared.hh +++ b/src/libmain/shared.hh @@ -7,25 +7,28 @@ #include -/* These are not implemented here, but must be implemented by a - program linking against libmain. */ +namespace nix { -/* Main program. Called by main() after the ATerm library has been - initialised and some default arguments have been processed (and - removed from `args'). main() will catch all exceptions. */ -void run(nix::Strings args); +MakeError(UsageError, nix::Error); -/* Should print a help message to stdout and return. */ -void printHelp(); +class Exit : public std::exception +{ +public: + int status; + Exit() : status(0) { } + Exit(int status) : status(status) { } +}; -extern std::string programId; +class StoreAPI; +int handleExceptions(const string & programName, std::function fun); -namespace nix { +void initNix(); -MakeError(UsageError, nix::Error); +void parseCmdLine(int argc, char * * argv, + std::function parseArg); -class StoreAPI; +void printVersion(const string & programName); /* Ugh. No better place to put this. */ void printGCWarning(); @@ -36,6 +39,9 @@ void printMissing(const PathSet & willBuild, const PathSet & willSubstitute, const PathSet & unknown, unsigned long long downloadSize, unsigned long long narSize); +string getArg(const string & opt, + Strings::iterator & i, const Strings::iterator & end); + template N getIntArg(const string & opt, Strings::iterator & i, const Strings::iterator & end, bool allowUnit) { @@ -65,9 +71,4 @@ void showManPage(const string & name); extern volatile ::sig_atomic_t blockInt; -/* Exit code of the program. */ -extern int exitCode; - -extern char * * argvSaved; - } -- cgit v1.2.3