1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-27 21:01:16 +02:00

Refactor option handling

This commit is contained in:
Eelco Dolstra 2014-08-13 03:50:44 +02:00
parent 5bed74d1b0
commit 47e185847e
10 changed files with 503 additions and 531 deletions

View file

@ -7,26 +7,29 @@
#include <locale>
/* These are not implemented here, but must be implemented by a
program linking against libmain. */
/* 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);
/* Should print a help message to stdout and return. */
void printHelp();
extern std::string programId;
namespace nix {
MakeError(UsageError, nix::Error);
class Exit : public std::exception
{
public:
int status;
Exit() : status(0) { }
Exit(int status) : status(status) { }
};
class StoreAPI;
int handleExceptions(const string & programName, std::function<void()> fun);
void initNix();
void parseCmdLine(int argc, char * * argv,
std::function<bool(Strings::iterator & arg, const Strings::iterator & end)> parseArg);
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<class N> 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;
}