Refactor option handling
This commit is contained in:
parent
5bed74d1b0
commit
47e185847e
10 changed files with 503 additions and 531 deletions
|
@ -91,55 +91,49 @@ static void query(std::pair<FdSink, FdSource> & pipes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void run(Strings args)
|
int main(int argc, char * * argv)
|
||||||
{
|
{
|
||||||
if (args.empty())
|
return handleExceptions(argv[0], [&]() {
|
||||||
throw UsageError("download-via-ssh requires an argument");
|
initNix();
|
||||||
|
|
||||||
if (settings.sshSubstituterHosts.empty())
|
if (argc < 2)
|
||||||
return;
|
throw UsageError("download-via-ssh requires an argument");
|
||||||
|
|
||||||
std::cout << std::endl;
|
if (settings.sshSubstituterHosts.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
/* Pass on the location of the daemon client's SSH authentication
|
std::cout << std::endl;
|
||||||
socket. */
|
|
||||||
string sshAuthSock = settings.get("ssh-auth-sock", "");
|
|
||||||
if (sshAuthSock != "") setenv("SSH_AUTH_SOCK", sshAuthSock.c_str(), 1);
|
|
||||||
|
|
||||||
string host = settings.sshSubstituterHosts.front();
|
/* Pass on the location of the daemon client's SSH
|
||||||
std::pair<FdSink, FdSource> pipes = connect(host);
|
authentication socket. */
|
||||||
|
string sshAuthSock = settings.get("ssh-auth-sock", "");
|
||||||
|
if (sshAuthSock != "") setenv("SSH_AUTH_SOCK", sshAuthSock.c_str(), 1);
|
||||||
|
|
||||||
/* Exchange the greeting */
|
string host = settings.sshSubstituterHosts.front();
|
||||||
writeInt(SERVE_MAGIC_1, pipes.first);
|
std::pair<FdSink, FdSource> pipes = connect(host);
|
||||||
pipes.first.flush();
|
|
||||||
unsigned int magic = readInt(pipes.second);
|
|
||||||
if (magic != SERVE_MAGIC_2)
|
|
||||||
throw Error("protocol mismatch");
|
|
||||||
readInt(pipes.second); // Server version, unused for now
|
|
||||||
writeInt(SERVE_PROTOCOL_VERSION, pipes.first);
|
|
||||||
pipes.first.flush();
|
|
||||||
|
|
||||||
Strings::iterator i = args.begin();
|
/* Exchange the greeting */
|
||||||
if (*i == "--query")
|
writeInt(SERVE_MAGIC_1, pipes.first);
|
||||||
query(pipes);
|
pipes.first.flush();
|
||||||
else if (*i == "--substitute")
|
unsigned int magic = readInt(pipes.second);
|
||||||
if (args.size() != 3)
|
if (magic != SERVE_MAGIC_2)
|
||||||
throw UsageError("download-via-ssh: --substitute takes exactly two arguments");
|
throw Error("protocol mismatch");
|
||||||
else {
|
readInt(pipes.second); // Server version, unused for now
|
||||||
Path storePath = *++i;
|
writeInt(SERVE_PROTOCOL_VERSION, pipes.first);
|
||||||
Path destPath = *++i;
|
pipes.first.flush();
|
||||||
|
|
||||||
|
string arg = argv[1];
|
||||||
|
if (arg == "--query")
|
||||||
|
query(pipes);
|
||||||
|
else if (arg == "--substitute") {
|
||||||
|
if (argc != 4)
|
||||||
|
throw UsageError("download-via-ssh: --substitute takes exactly two arguments");
|
||||||
|
Path storePath = argv[2];
|
||||||
|
Path destPath = argv[3];
|
||||||
printMsg(lvlError, format("downloading `%1%' via SSH from `%2%'...") % storePath % host);
|
printMsg(lvlError, format("downloading `%1%' via SSH from `%2%'...") % storePath % host);
|
||||||
substitute(pipes, storePath, destPath);
|
substitute(pipes, storePath, destPath);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw UsageError(format("download-via-ssh: unknown command `%1%'") % *i);
|
throw UsageError(format("download-via-ssh: unknown command `%1%'") % arg);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void printHelp()
|
|
||||||
{
|
|
||||||
std::cerr << "Usage: download-via-ssh --query|--substitute store-path dest-path" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
string programId = "download-via-ssh";
|
|
||||||
|
|
|
@ -6,40 +6,45 @@
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
|
||||||
bool parseOptionArg(const string & arg, Strings::iterator & i,
|
bool parseAutoArgs(Strings::iterator & i,
|
||||||
const Strings::iterator & argsEnd, EvalState & state,
|
const Strings::iterator & argsEnd, std::map<string, string> & res)
|
||||||
Bindings & autoArgs)
|
|
||||||
{
|
{
|
||||||
|
string arg = *i;
|
||||||
if (arg != "--arg" && arg != "--argstr") return false;
|
if (arg != "--arg" && arg != "--argstr") return false;
|
||||||
|
|
||||||
UsageError error(format("`%1%' requires two arguments") % arg);
|
UsageError error(format("`%1%' requires two arguments") % arg);
|
||||||
|
|
||||||
if (i == argsEnd) throw error;
|
if (++i == argsEnd) throw error;
|
||||||
string name = *i++;
|
string name = *i;
|
||||||
if (i == argsEnd) throw error;
|
if (++i == argsEnd) throw error;
|
||||||
string value = *i++;
|
string value = *i;
|
||||||
|
|
||||||
/* !!! check for duplicates! */
|
res[name] = (arg == "--arg" ? 'E' : 'S') + value;
|
||||||
Value * v = state.allocValue();
|
|
||||||
autoArgs.push_back(Attr(state.symbols.create(name), v));
|
|
||||||
|
|
||||||
if (arg == "--arg")
|
|
||||||
state.mkThunk_(*v, state.parseExprFromString(value, absPath(".")));
|
|
||||||
else
|
|
||||||
mkString(*v, value);
|
|
||||||
|
|
||||||
autoArgs.sort(); // !!! inefficient
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool parseSearchPathArg(const string & arg, Strings::iterator & i,
|
void evalAutoArgs(EvalState & state, std::map<string, string> & in, Bindings & out)
|
||||||
|
{
|
||||||
|
for (auto & i: in) {
|
||||||
|
Value * v = state.allocValue();
|
||||||
|
if (i.second[0] == 'E')
|
||||||
|
state.mkThunk_(*v, state.parseExprFromString(string(i.second, 1), absPath(".")));
|
||||||
|
else
|
||||||
|
mkString(*v, string(i.second, 1));
|
||||||
|
out.push_back(Attr(state.symbols.create(i.first), v));
|
||||||
|
}
|
||||||
|
out.sort();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool parseSearchPathArg(Strings::iterator & i,
|
||||||
const Strings::iterator & argsEnd, Strings & searchPath)
|
const Strings::iterator & argsEnd, Strings & searchPath)
|
||||||
{
|
{
|
||||||
if (arg != "-I") return false;
|
if (*i != "-I") return false;
|
||||||
if (i == argsEnd) throw UsageError(format("`%1%' requires an argument") % arg);;
|
if (++i == argsEnd) throw UsageError("`-I' requires an argument");
|
||||||
searchPath.push_back(*i++);
|
searchPath.push_back(*i);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,11 +5,12 @@
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
/* Some common option parsing between nix-env and nix-instantiate. */
|
/* Some common option parsing between nix-env and nix-instantiate. */
|
||||||
bool parseOptionArg(const string & arg, Strings::iterator & i,
|
bool parseAutoArgs(Strings::iterator & i,
|
||||||
const Strings::iterator & argsEnd, EvalState & state,
|
const Strings::iterator & argsEnd, std::map<string, string> & res);
|
||||||
Bindings & autoArgs);
|
|
||||||
|
|
||||||
bool parseSearchPathArg(const string & arg, Strings::iterator & i,
|
void evalAutoArgs(EvalState & state, std::map<string, string> & in, Bindings & out);
|
||||||
|
|
||||||
|
bool parseSearchPathArg(Strings::iterator & i,
|
||||||
const Strings::iterator & argsEnd, Strings & searchPath);
|
const Strings::iterator & argsEnd, Strings & searchPath);
|
||||||
|
|
||||||
Path lookupFileArg(EvalState & state, string s);
|
Path lookupFileArg(EvalState & state, string s);
|
||||||
|
|
|
@ -100,10 +100,16 @@ string getArg(const string & opt,
|
||||||
void detectStackOverflow();
|
void detectStackOverflow();
|
||||||
|
|
||||||
|
|
||||||
/* Initialize and reorder arguments, then call the actual argument
|
void initNix()
|
||||||
processor. */
|
|
||||||
static void initAndRun(int argc, char * * argv)
|
|
||||||
{
|
{
|
||||||
|
/* Turn on buffering for cerr. */
|
||||||
|
#if HAVE_PUBSETBUF
|
||||||
|
static char buf[1024];
|
||||||
|
std::cerr.rdbuf()->pubsetbuf(buf, sizeof(buf));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
|
||||||
settings.processEnvironment();
|
settings.processEnvironment();
|
||||||
settings.loadConfFile();
|
settings.loadConfFile();
|
||||||
|
|
||||||
|
@ -144,6 +150,14 @@ static void initAndRun(int argc, char * * argv)
|
||||||
gettimeofday(&tv, 0);
|
gettimeofday(&tv, 0);
|
||||||
srandom(tv.tv_usec);
|
srandom(tv.tv_usec);
|
||||||
|
|
||||||
|
if (char *pack = getenv("_NIX_OPTIONS"))
|
||||||
|
settings.unpack(pack);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void parseCmdLine(int argc, char * * argv,
|
||||||
|
std::function<bool(Strings::iterator & arg, const Strings::iterator & end)> parseArg)
|
||||||
|
{
|
||||||
/* Put the arguments in a vector. */
|
/* Put the arguments in a vector. */
|
||||||
Strings args, remaining;
|
Strings args, remaining;
|
||||||
while (argc--) args.push_back(*argv++);
|
while (argc--) args.push_back(*argv++);
|
||||||
|
@ -164,7 +178,6 @@ static void initAndRun(int argc, char * * argv)
|
||||||
} else remaining.push_back(arg);
|
} else remaining.push_back(arg);
|
||||||
}
|
}
|
||||||
args = remaining;
|
args = remaining;
|
||||||
remaining.clear();
|
|
||||||
|
|
||||||
/* Process default options. */
|
/* Process default options. */
|
||||||
for (Strings::iterator i = args.begin(); i != args.end(); ++i) {
|
for (Strings::iterator i = args.begin(); i != args.end(); ++i) {
|
||||||
|
@ -179,14 +192,6 @@ static void initAndRun(int argc, char * * argv)
|
||||||
settings.buildVerbosity = lvlVomit;
|
settings.buildVerbosity = lvlVomit;
|
||||||
else if (arg == "--print-build-trace")
|
else if (arg == "--print-build-trace")
|
||||||
settings.printBuildTrace = true;
|
settings.printBuildTrace = true;
|
||||||
else if (arg == "--help") {
|
|
||||||
printHelp();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (arg == "--version") {
|
|
||||||
std::cout << format("%1% (Nix) %2%") % programId % nixVersion << std::endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (arg == "--keep-failed" || arg == "-K")
|
else if (arg == "--keep-failed" || arg == "-K")
|
||||||
settings.keepFailed = true;
|
settings.keepFailed = true;
|
||||||
else if (arg == "--keep-going" || arg == "-k")
|
else if (arg == "--keep-going" || arg == "-k")
|
||||||
|
@ -216,25 +221,20 @@ static void initAndRun(int argc, char * * argv)
|
||||||
string value = *i;
|
string value = *i;
|
||||||
settings.set(name, value);
|
settings.set(name, value);
|
||||||
}
|
}
|
||||||
else if (arg == "--arg" || arg == "--argstr") {
|
else {
|
||||||
remaining.push_back(arg);
|
if (!parseArg(i, args.end()))
|
||||||
++i; if (i == args.end()) throw UsageError(format("`%1%' requires two arguments") % arg);
|
throw UsageError(format("unrecognised option `%1%'") % *i);
|
||||||
remaining.push_back(*i);
|
|
||||||
++i; if (i == args.end()) throw UsageError(format("`%1%' requires two arguments") % arg);
|
|
||||||
remaining.push_back(*i);
|
|
||||||
}
|
}
|
||||||
else remaining.push_back(arg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (char *pack = getenv("_NIX_OPTIONS"))
|
|
||||||
settings.unpack(pack);
|
|
||||||
|
|
||||||
settings.update();
|
settings.update();
|
||||||
|
}
|
||||||
|
|
||||||
run(remaining);
|
|
||||||
|
|
||||||
/* Close the Nix database. */
|
void printVersion(const string & programName)
|
||||||
store.reset((StoreAPI *) 0);
|
{
|
||||||
|
std::cout << format("%1% (Nix) %2%") % programName % nixVersion << std::endl;
|
||||||
|
throw Exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -246,30 +246,11 @@ void showManPage(const string & name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int exitCode = 0;
|
int handleExceptions(const string & programName, std::function<void()> fun)
|
||||||
char * * argvSaved = 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static char buf[1024];
|
|
||||||
|
|
||||||
int main(int argc, char * * argv)
|
|
||||||
{
|
{
|
||||||
using namespace nix;
|
|
||||||
|
|
||||||
argvSaved = argv;
|
|
||||||
|
|
||||||
/* Turn on buffering for cerr. */
|
|
||||||
#if HAVE_PUBSETBUF
|
|
||||||
std::cerr.rdbuf()->pubsetbuf(buf, sizeof(buf));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::ios::sync_with_stdio(false);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
initAndRun(argc, argv);
|
fun();
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
/* Subtle: we have to make sure that any `interrupted'
|
/* Subtle: we have to make sure that any `interrupted'
|
||||||
condition is discharged before we reach printMsg()
|
condition is discharged before we reach printMsg()
|
||||||
|
@ -279,12 +260,14 @@ int main(int argc, char * * argv)
|
||||||
_isInterrupted = 0;
|
_isInterrupted = 0;
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
} catch (Exit & e) {
|
||||||
|
return e.status;
|
||||||
} catch (UsageError & e) {
|
} catch (UsageError & e) {
|
||||||
printMsg(lvlError,
|
printMsg(lvlError,
|
||||||
format(
|
format(
|
||||||
"error: %1%\n"
|
"error: %1%\n"
|
||||||
"Try `%2% --help' for more information.")
|
"Try `%2% --help' for more information.")
|
||||||
% e.what() % programId);
|
% e.what() % programName);
|
||||||
return 1;
|
return 1;
|
||||||
} catch (BaseError & e) {
|
} catch (BaseError & e) {
|
||||||
printMsg(lvlError, format("error: %1%%2%") % (settings.showTrace ? e.prefix() : "") % e.msg());
|
printMsg(lvlError, format("error: %1%%2%") % (settings.showTrace ? e.prefix() : "") % e.msg());
|
||||||
|
@ -299,5 +282,8 @@ int main(int argc, char * * argv)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return exitCode;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,26 +7,29 @@
|
||||||
#include <locale>
|
#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 {
|
namespace nix {
|
||||||
|
|
||||||
MakeError(UsageError, nix::Error);
|
MakeError(UsageError, nix::Error);
|
||||||
|
|
||||||
|
class Exit : public std::exception
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int status;
|
||||||
|
Exit() : status(0) { }
|
||||||
|
Exit(int status) : status(status) { }
|
||||||
|
};
|
||||||
|
|
||||||
class StoreAPI;
|
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. */
|
/* Ugh. No better place to put this. */
|
||||||
void printGCWarning();
|
void printGCWarning();
|
||||||
|
|
||||||
|
@ -36,6 +39,9 @@ void printMissing(const PathSet & willBuild,
|
||||||
const PathSet & willSubstitute, const PathSet & unknown,
|
const PathSet & willSubstitute, const PathSet & unknown,
|
||||||
unsigned long long downloadSize, unsigned long long narSize);
|
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,
|
template<class N> N getIntArg(const string & opt,
|
||||||
Strings::iterator & i, const Strings::iterator & end, bool allowUnit)
|
Strings::iterator & i, const Strings::iterator & end, bool allowUnit)
|
||||||
{
|
{
|
||||||
|
@ -65,9 +71,4 @@ void showManPage(const string & name);
|
||||||
|
|
||||||
extern volatile ::sig_atomic_t blockInt;
|
extern volatile ::sig_atomic_t blockInt;
|
||||||
|
|
||||||
/* Exit code of the program. */
|
|
||||||
extern int exitCode;
|
|
||||||
|
|
||||||
extern char * * argvSaved;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -645,8 +645,10 @@ bool matchUser(const string & user, const string & group, const Strings & users)
|
||||||
#define SD_LISTEN_FDS_START 3
|
#define SD_LISTEN_FDS_START 3
|
||||||
|
|
||||||
|
|
||||||
static void daemonLoop()
|
static void daemonLoop(char * * argv)
|
||||||
{
|
{
|
||||||
|
chdir("/");
|
||||||
|
|
||||||
/* Get rid of children automatically; don't let them become
|
/* Get rid of children automatically; don't let them become
|
||||||
zombies. */
|
zombies. */
|
||||||
setSigChldAction(true);
|
setSigChldAction(true);
|
||||||
|
@ -766,9 +768,9 @@ static void daemonLoop()
|
||||||
setSigChldAction(false);
|
setSigChldAction(false);
|
||||||
|
|
||||||
/* For debugging, stuff the pid into argv[1]. */
|
/* For debugging, stuff the pid into argv[1]. */
|
||||||
if (clientPid != -1 && argvSaved[1]) {
|
if (clientPid != -1 && argv[1]) {
|
||||||
string processName = int2String(clientPid);
|
string processName = int2String(clientPid);
|
||||||
strncpy(argvSaved[1], processName.c_str(), strlen(argvSaved[1]));
|
strncpy(argv[1], processName.c_str(), strlen(argv[1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handle the connection. */
|
/* Handle the connection. */
|
||||||
|
@ -792,18 +794,27 @@ void run(Strings args)
|
||||||
{
|
{
|
||||||
for (Strings::iterator i = args.begin(); i != args.end(); ) {
|
for (Strings::iterator i = args.begin(); i != args.end(); ) {
|
||||||
string arg = *i++;
|
string arg = *i++;
|
||||||
if (arg == "--daemon") /* ignored for backwards compatibility */;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
chdir("/");
|
|
||||||
daemonLoop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void printHelp()
|
int main(int argc, char * * argv)
|
||||||
{
|
{
|
||||||
showManPage("nix-daemon");
|
return handleExceptions(argv[0], [&]() {
|
||||||
|
initNix();
|
||||||
|
|
||||||
|
parseCmdLine(argc, argv, [&](Strings::iterator & arg, const Strings::iterator & end) {
|
||||||
|
if (*arg == "--daemon")
|
||||||
|
; /* ignored for backwards compatibility */
|
||||||
|
else if (*arg == "--help")
|
||||||
|
showManPage("nix-daemon");
|
||||||
|
else if (*arg == "--version")
|
||||||
|
printVersion("nix-daemon");
|
||||||
|
else return false;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
daemonLoop(argv);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
string programId = "nix-daemon";
|
|
||||||
|
|
|
@ -52,24 +52,17 @@ struct Globals
|
||||||
{
|
{
|
||||||
InstallSourceInfo instSource;
|
InstallSourceInfo instSource;
|
||||||
Path profile;
|
Path profile;
|
||||||
EvalState state;
|
std::shared_ptr<EvalState> state;
|
||||||
bool dryRun;
|
bool dryRun;
|
||||||
bool preserveInstalled;
|
bool preserveInstalled;
|
||||||
bool removeAll;
|
bool removeAll;
|
||||||
string forceName;
|
string forceName;
|
||||||
bool prebuiltOnly;
|
bool prebuiltOnly;
|
||||||
Globals(const Strings & searchPath) : state(searchPath) { }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
typedef void (* Operation) (Globals & globals,
|
typedef void (* Operation) (Globals & globals,
|
||||||
Strings args, Strings opFlags, Strings opArgs);
|
Strings opFlags, Strings opArgs);
|
||||||
|
|
||||||
|
|
||||||
void printHelp()
|
|
||||||
{
|
|
||||||
showManPage("nix-env");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static string needArg(Strings::iterator & i,
|
static string needArg(Strings::iterator & i,
|
||||||
|
@ -467,11 +460,11 @@ static void installDerivations(Globals & globals,
|
||||||
|
|
||||||
/* Get the set of user environment elements to be installed. */
|
/* Get the set of user environment elements to be installed. */
|
||||||
DrvInfos newElems, newElemsTmp;
|
DrvInfos newElems, newElemsTmp;
|
||||||
queryInstSources(globals.state, globals.instSource, args, newElemsTmp, true);
|
queryInstSources(*globals.state, globals.instSource, args, newElemsTmp, true);
|
||||||
|
|
||||||
/* If --prebuilt-only is given, filter out source-only packages. */
|
/* If --prebuilt-only is given, filter out source-only packages. */
|
||||||
foreach (DrvInfos::iterator, i, newElemsTmp)
|
foreach (DrvInfos::iterator, i, newElemsTmp)
|
||||||
if (!globals.prebuiltOnly || isPrebuilt(globals.state, *i))
|
if (!globals.prebuiltOnly || isPrebuilt(*globals.state, *i))
|
||||||
newElems.push_back(*i);
|
newElems.push_back(*i);
|
||||||
|
|
||||||
StringSet newNames;
|
StringSet newNames;
|
||||||
|
@ -494,7 +487,7 @@ static void installDerivations(Globals & globals,
|
||||||
/* Add in the already installed derivations, unless they have
|
/* Add in the already installed derivations, unless they have
|
||||||
the same name as a to-be-installed element. */
|
the same name as a to-be-installed element. */
|
||||||
if (!globals.removeAll) {
|
if (!globals.removeAll) {
|
||||||
DrvInfos installedElems = queryInstalled(globals.state, profile);
|
DrvInfos installedElems = queryInstalled(*globals.state, profile);
|
||||||
|
|
||||||
foreach (DrvInfos::iterator, i, installedElems) {
|
foreach (DrvInfos::iterator, i, installedElems) {
|
||||||
DrvName drvName(i->name);
|
DrvName drvName(i->name);
|
||||||
|
@ -510,18 +503,17 @@ static void installDerivations(Globals & globals,
|
||||||
printMsg(lvlInfo, format("installing `%1%'") % i->name);
|
printMsg(lvlInfo, format("installing `%1%'") % i->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
printMissing(globals.state, newElems);
|
printMissing(*globals.state, newElems);
|
||||||
|
|
||||||
if (globals.dryRun) return;
|
if (globals.dryRun) return;
|
||||||
|
|
||||||
if (createUserEnv(globals.state, allElems,
|
if (createUserEnv(*globals.state, allElems,
|
||||||
profile, settings.envKeepDerivations, lockToken)) break;
|
profile, settings.envKeepDerivations, lockToken)) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void opInstall(Globals & globals,
|
static void opInstall(Globals & globals, Strings opFlags, Strings opArgs)
|
||||||
Strings args, Strings opFlags, Strings opArgs)
|
|
||||||
{
|
{
|
||||||
for (Strings::iterator i = opFlags.begin(); i != opFlags.end(); ) {
|
for (Strings::iterator i = opFlags.begin(); i != opFlags.end(); ) {
|
||||||
string arg = *i++;
|
string arg = *i++;
|
||||||
|
@ -553,11 +545,11 @@ static void upgradeDerivations(Globals & globals,
|
||||||
while (true) {
|
while (true) {
|
||||||
string lockToken = optimisticLockProfile(globals.profile);
|
string lockToken = optimisticLockProfile(globals.profile);
|
||||||
|
|
||||||
DrvInfos installedElems = queryInstalled(globals.state, globals.profile);
|
DrvInfos installedElems = queryInstalled(*globals.state, globals.profile);
|
||||||
|
|
||||||
/* Fetch all derivations from the input file. */
|
/* Fetch all derivations from the input file. */
|
||||||
DrvInfos availElems;
|
DrvInfos availElems;
|
||||||
queryInstSources(globals.state, globals.instSource, args, availElems, false);
|
queryInstSources(*globals.state, globals.instSource, args, availElems, false);
|
||||||
|
|
||||||
/* Go through all installed derivations. */
|
/* Go through all installed derivations. */
|
||||||
DrvInfos newElems;
|
DrvInfos newElems;
|
||||||
|
@ -582,7 +574,7 @@ static void upgradeDerivations(Globals & globals,
|
||||||
foreach (DrvInfos::iterator, j, availElems) {
|
foreach (DrvInfos::iterator, j, availElems) {
|
||||||
DrvName newName(j->name);
|
DrvName newName(j->name);
|
||||||
if (newName.name == drvName.name) {
|
if (newName.name == drvName.name) {
|
||||||
int d = comparePriorities(globals.state, *i, *j);
|
int d = comparePriorities(*globals.state, *i, *j);
|
||||||
if (d == 0) d = compareVersions(drvName.version, newName.version);
|
if (d == 0) d = compareVersions(drvName.version, newName.version);
|
||||||
if ((upgradeType == utLt && d < 0) ||
|
if ((upgradeType == utLt && d < 0) ||
|
||||||
(upgradeType == utLeq && d <= 0) ||
|
(upgradeType == utLeq && d <= 0) ||
|
||||||
|
@ -591,10 +583,10 @@ static void upgradeDerivations(Globals & globals,
|
||||||
{
|
{
|
||||||
int d2 = -1;
|
int d2 = -1;
|
||||||
if (bestElem != availElems.end()) {
|
if (bestElem != availElems.end()) {
|
||||||
d2 = comparePriorities(globals.state, *bestElem, *j);
|
d2 = comparePriorities(*globals.state, *bestElem, *j);
|
||||||
if (d2 == 0) d2 = compareVersions(bestName.version, newName.version);
|
if (d2 == 0) d2 = compareVersions(bestName.version, newName.version);
|
||||||
}
|
}
|
||||||
if (d2 < 0 && (!globals.prebuiltOnly || isPrebuilt(globals.state, *j))) {
|
if (d2 < 0 && (!globals.prebuiltOnly || isPrebuilt(*globals.state, *j))) {
|
||||||
bestElem = j;
|
bestElem = j;
|
||||||
bestName = newName;
|
bestName = newName;
|
||||||
}
|
}
|
||||||
|
@ -618,18 +610,17 @@ static void upgradeDerivations(Globals & globals,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printMissing(globals.state, newElems);
|
printMissing(*globals.state, newElems);
|
||||||
|
|
||||||
if (globals.dryRun) return;
|
if (globals.dryRun) return;
|
||||||
|
|
||||||
if (createUserEnv(globals.state, newElems,
|
if (createUserEnv(*globals.state, newElems,
|
||||||
globals.profile, settings.envKeepDerivations, lockToken)) break;
|
globals.profile, settings.envKeepDerivations, lockToken)) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void opUpgrade(Globals & globals,
|
static void opUpgrade(Globals & globals, Strings opFlags, Strings opArgs)
|
||||||
Strings args, Strings opFlags, Strings opArgs)
|
|
||||||
{
|
{
|
||||||
UpgradeType upgradeType = utLt;
|
UpgradeType upgradeType = utLt;
|
||||||
for (Strings::iterator i = opFlags.begin(); i != opFlags.end(); ) {
|
for (Strings::iterator i = opFlags.begin(); i != opFlags.end(); ) {
|
||||||
|
@ -655,8 +646,7 @@ static void setMetaFlag(EvalState & state, DrvInfo & drv,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void opSetFlag(Globals & globals,
|
static void opSetFlag(Globals & globals, Strings opFlags, Strings opArgs)
|
||||||
Strings args, Strings opFlags, Strings opArgs)
|
|
||||||
{
|
{
|
||||||
if (opFlags.size() > 0)
|
if (opFlags.size() > 0)
|
||||||
throw UsageError(format("unknown flag `%1%'") % opFlags.front());
|
throw UsageError(format("unknown flag `%1%'") % opFlags.front());
|
||||||
|
@ -671,7 +661,7 @@ static void opSetFlag(Globals & globals,
|
||||||
while (true) {
|
while (true) {
|
||||||
string lockToken = optimisticLockProfile(globals.profile);
|
string lockToken = optimisticLockProfile(globals.profile);
|
||||||
|
|
||||||
DrvInfos installedElems = queryInstalled(globals.state, globals.profile);
|
DrvInfos installedElems = queryInstalled(*globals.state, globals.profile);
|
||||||
|
|
||||||
/* Update all matching derivations. */
|
/* Update all matching derivations. */
|
||||||
foreach (DrvInfos::iterator, i, installedElems) {
|
foreach (DrvInfos::iterator, i, installedElems) {
|
||||||
|
@ -680,7 +670,7 @@ static void opSetFlag(Globals & globals,
|
||||||
if (j->matches(drvName)) {
|
if (j->matches(drvName)) {
|
||||||
printMsg(lvlInfo, format("setting flag on `%1%'") % i->name);
|
printMsg(lvlInfo, format("setting flag on `%1%'") % i->name);
|
||||||
j->hits++;
|
j->hits++;
|
||||||
setMetaFlag(globals.state, *i, flagName, flagValue);
|
setMetaFlag(*globals.state, *i, flagName, flagValue);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -688,14 +678,13 @@ static void opSetFlag(Globals & globals,
|
||||||
checkSelectorUse(selectors);
|
checkSelectorUse(selectors);
|
||||||
|
|
||||||
/* Write the new user environment. */
|
/* Write the new user environment. */
|
||||||
if (createUserEnv(globals.state, installedElems,
|
if (createUserEnv(*globals.state, installedElems,
|
||||||
globals.profile, settings.envKeepDerivations, lockToken)) break;
|
globals.profile, settings.envKeepDerivations, lockToken)) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void opSet(Globals & globals,
|
static void opSet(Globals & globals, Strings opFlags, Strings opArgs)
|
||||||
Strings args, Strings opFlags, Strings opArgs)
|
|
||||||
{
|
{
|
||||||
for (Strings::iterator i = opFlags.begin(); i != opFlags.end(); ) {
|
for (Strings::iterator i = opFlags.begin(); i != opFlags.end(); ) {
|
||||||
string arg = *i++;
|
string arg = *i++;
|
||||||
|
@ -704,7 +693,7 @@ static void opSet(Globals & globals,
|
||||||
}
|
}
|
||||||
|
|
||||||
DrvInfos elems;
|
DrvInfos elems;
|
||||||
queryInstSources(globals.state, globals.instSource, opArgs, elems, true);
|
queryInstSources(*globals.state, globals.instSource, opArgs, elems, true);
|
||||||
|
|
||||||
if (elems.size() != 1)
|
if (elems.size() != 1)
|
||||||
throw Error("--set requires exactly one derivation");
|
throw Error("--set requires exactly one derivation");
|
||||||
|
@ -715,7 +704,7 @@ static void opSet(Globals & globals,
|
||||||
PathSet paths = singleton<PathSet>(drv.queryDrvPath());
|
PathSet paths = singleton<PathSet>(drv.queryDrvPath());
|
||||||
printMissing(*store, paths);
|
printMissing(*store, paths);
|
||||||
if (globals.dryRun) return;
|
if (globals.dryRun) return;
|
||||||
store->buildPaths(paths, globals.state.repair ? bmRepair : bmNormal);
|
store->buildPaths(paths, globals.state->repair ? bmRepair : bmNormal);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printMissing(*store, singleton<PathSet>(drv.queryOutPath()));
|
printMissing(*store, singleton<PathSet>(drv.queryOutPath()));
|
||||||
|
@ -735,7 +724,7 @@ static void uninstallDerivations(Globals & globals, Strings & selectors,
|
||||||
while (true) {
|
while (true) {
|
||||||
string lockToken = optimisticLockProfile(profile);
|
string lockToken = optimisticLockProfile(profile);
|
||||||
|
|
||||||
DrvInfos installedElems = queryInstalled(globals.state, profile);
|
DrvInfos installedElems = queryInstalled(*globals.state, profile);
|
||||||
DrvInfos newElems;
|
DrvInfos newElems;
|
||||||
|
|
||||||
foreach (DrvInfos::iterator, i, installedElems) {
|
foreach (DrvInfos::iterator, i, installedElems) {
|
||||||
|
@ -756,14 +745,13 @@ static void uninstallDerivations(Globals & globals, Strings & selectors,
|
||||||
|
|
||||||
if (globals.dryRun) return;
|
if (globals.dryRun) return;
|
||||||
|
|
||||||
if (createUserEnv(globals.state, newElems,
|
if (createUserEnv(*globals.state, newElems,
|
||||||
profile, settings.envKeepDerivations, lockToken)) break;
|
profile, settings.envKeepDerivations, lockToken)) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void opUninstall(Globals & globals,
|
static void opUninstall(Globals & globals, Strings opFlags, Strings opArgs)
|
||||||
Strings args, Strings opFlags, Strings opArgs)
|
|
||||||
{
|
{
|
||||||
if (opFlags.size() > 0)
|
if (opFlags.size() > 0)
|
||||||
throw UsageError(format("unknown flag `%1%'") % opFlags.front());
|
throw UsageError(format("unknown flag `%1%'") % opFlags.front());
|
||||||
|
@ -887,15 +875,14 @@ static void queryJSON(Globals & globals, vector<DrvInfo> & elems)
|
||||||
cout << "null";
|
cout << "null";
|
||||||
} else {
|
} else {
|
||||||
PathSet context;
|
PathSet context;
|
||||||
printValueAsJSON(globals.state, true, *v, cout, context);
|
printValueAsJSON(*globals.state, true, *v, cout, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void opQuery(Globals & globals,
|
static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
|
||||||
Strings args, Strings opFlags, Strings opArgs)
|
|
||||||
{
|
{
|
||||||
Strings remaining;
|
Strings remaining;
|
||||||
string attrPath;
|
string attrPath;
|
||||||
|
@ -916,7 +903,7 @@ static void opQuery(Globals & globals,
|
||||||
|
|
||||||
settings.readOnlyMode = true; /* makes evaluation a bit faster */
|
settings.readOnlyMode = true; /* makes evaluation a bit faster */
|
||||||
|
|
||||||
for (Strings::iterator i = args.begin(); i != args.end(); ) {
|
for (Strings::iterator i = opFlags.begin(); i != opFlags.end(); ) {
|
||||||
string arg = *i++;
|
string arg = *i++;
|
||||||
if (arg == "--status" || arg == "-s") printStatus = true;
|
if (arg == "--status" || arg == "-s") printStatus = true;
|
||||||
else if (arg == "--no-name") printName = false;
|
else if (arg == "--no-name") printName = false;
|
||||||
|
@ -932,10 +919,9 @@ static void opQuery(Globals & globals,
|
||||||
else if (arg == "--json") jsonOutput = true;
|
else if (arg == "--json") jsonOutput = true;
|
||||||
else if (arg == "--attr-path" || arg == "-P") printAttrPath = true;
|
else if (arg == "--attr-path" || arg == "-P") printAttrPath = true;
|
||||||
else if (arg == "--attr" || arg == "-A")
|
else if (arg == "--attr" || arg == "-A")
|
||||||
attrPath = needArg(i, args, arg);
|
attrPath = needArg(i, opFlags, arg);
|
||||||
else if (arg[0] == '-')
|
else
|
||||||
throw UsageError(format("unknown flag `%1%'") % arg);
|
throw UsageError(format("unknown flag `%1%'") % arg);
|
||||||
else remaining.push_back(arg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -943,16 +929,16 @@ static void opQuery(Globals & globals,
|
||||||
DrvInfos availElems, installedElems;
|
DrvInfos availElems, installedElems;
|
||||||
|
|
||||||
if (source == sInstalled || compareVersions || printStatus)
|
if (source == sInstalled || compareVersions || printStatus)
|
||||||
installedElems = queryInstalled(globals.state, globals.profile);
|
installedElems = queryInstalled(*globals.state, globals.profile);
|
||||||
|
|
||||||
if (source == sAvailable || compareVersions)
|
if (source == sAvailable || compareVersions)
|
||||||
loadDerivations(globals.state, globals.instSource.nixExprPath,
|
loadDerivations(*globals.state, globals.instSource.nixExprPath,
|
||||||
globals.instSource.systemFilter, globals.instSource.autoArgs,
|
globals.instSource.systemFilter, globals.instSource.autoArgs,
|
||||||
attrPath, availElems);
|
attrPath, availElems);
|
||||||
|
|
||||||
DrvInfos elems_ = filterBySelector(globals.state,
|
DrvInfos elems_ = filterBySelector(*globals.state,
|
||||||
source == sInstalled ? installedElems : availElems,
|
source == sInstalled ? installedElems : availElems,
|
||||||
remaining, false);
|
opArgs, false);
|
||||||
|
|
||||||
DrvInfos & otherElems(source == sInstalled ? availElems : installedElems);
|
DrvInfos & otherElems(source == sInstalled ? availElems : installedElems);
|
||||||
|
|
||||||
|
@ -1173,8 +1159,7 @@ static void opQuery(Globals & globals,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void opSwitchProfile(Globals & globals,
|
static void opSwitchProfile(Globals & globals, Strings opFlags, Strings opArgs)
|
||||||
Strings args, Strings opFlags, Strings opArgs)
|
|
||||||
{
|
{
|
||||||
if (opFlags.size() > 0)
|
if (opFlags.size() > 0)
|
||||||
throw UsageError(format("unknown flag `%1%'") % opFlags.front());
|
throw UsageError(format("unknown flag `%1%'") % opFlags.front());
|
||||||
|
@ -1222,8 +1207,7 @@ static void switchGeneration(Globals & globals, int dstGen)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void opSwitchGeneration(Globals & globals,
|
static void opSwitchGeneration(Globals & globals, Strings opFlags, Strings opArgs)
|
||||||
Strings args, Strings opFlags, Strings opArgs)
|
|
||||||
{
|
{
|
||||||
if (opFlags.size() > 0)
|
if (opFlags.size() > 0)
|
||||||
throw UsageError(format("unknown flag `%1%'") % opFlags.front());
|
throw UsageError(format("unknown flag `%1%'") % opFlags.front());
|
||||||
|
@ -1238,8 +1222,7 @@ static void opSwitchGeneration(Globals & globals,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void opRollback(Globals & globals,
|
static void opRollback(Globals & globals, Strings opFlags, Strings opArgs)
|
||||||
Strings args, Strings opFlags, Strings opArgs)
|
|
||||||
{
|
{
|
||||||
if (opFlags.size() > 0)
|
if (opFlags.size() > 0)
|
||||||
throw UsageError(format("unknown flag `%1%'") % opFlags.front());
|
throw UsageError(format("unknown flag `%1%'") % opFlags.front());
|
||||||
|
@ -1250,8 +1233,7 @@ static void opRollback(Globals & globals,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void opListGenerations(Globals & globals,
|
static void opListGenerations(Globals & globals, Strings opFlags, Strings opArgs)
|
||||||
Strings args, Strings opFlags, Strings opArgs)
|
|
||||||
{
|
{
|
||||||
if (opFlags.size() > 0)
|
if (opFlags.size() > 0)
|
||||||
throw UsageError(format("unknown flag `%1%'") % opFlags.front());
|
throw UsageError(format("unknown flag `%1%'") % opFlags.front());
|
||||||
|
@ -1288,8 +1270,7 @@ static void deleteGeneration2(Globals & globals, unsigned int gen)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void opDeleteGenerations(Globals & globals,
|
static void opDeleteGenerations(Globals & globals, Strings opFlags, Strings opArgs)
|
||||||
Strings args, Strings opFlags, Strings opArgs)
|
|
||||||
{
|
{
|
||||||
if (opFlags.size() > 0)
|
if (opFlags.size() > 0)
|
||||||
throw UsageError(format("unknown flag `%1%'") % opFlags.front());
|
throw UsageError(format("unknown flag `%1%'") % opFlags.front());
|
||||||
|
@ -1348,110 +1329,115 @@ static void opDeleteGenerations(Globals & globals,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void run(Strings args)
|
int main(int argc, char * * argv)
|
||||||
{
|
{
|
||||||
Strings opFlags, opArgs, remaining;
|
return handleExceptions(argv[0], [&]() {
|
||||||
Operation op = 0;
|
initNix();
|
||||||
|
|
||||||
/* FIXME: hack. */
|
Strings opFlags, opArgs, searchPath;
|
||||||
Strings searchPath;
|
std::map<string, string> autoArgs_;
|
||||||
Strings args2;
|
Operation op = 0;
|
||||||
for (Strings::iterator i = args.begin(); i != args.end(); ) {
|
bool repair = false;
|
||||||
string arg = *i++;
|
string file;
|
||||||
if (!parseSearchPathArg(arg, i, args.end(), searchPath))
|
|
||||||
args2.push_back(arg);
|
|
||||||
}
|
|
||||||
args = args2;
|
|
||||||
|
|
||||||
Globals globals(searchPath);
|
Globals globals;
|
||||||
|
|
||||||
globals.instSource.type = srcUnknown;
|
globals.instSource.type = srcUnknown;
|
||||||
globals.instSource.nixExprPath = getDefNixExprPath();
|
globals.instSource.nixExprPath = getDefNixExprPath();
|
||||||
globals.instSource.systemFilter = "*";
|
globals.instSource.systemFilter = "*";
|
||||||
|
|
||||||
globals.dryRun = false;
|
globals.dryRun = false;
|
||||||
globals.preserveInstalled = false;
|
globals.preserveInstalled = false;
|
||||||
globals.removeAll = false;
|
globals.removeAll = false;
|
||||||
globals.prebuiltOnly = false;
|
globals.prebuiltOnly = false;
|
||||||
|
|
||||||
for (Strings::iterator i = args.begin(); i != args.end(); ) {
|
parseCmdLine(argc, argv, [&](Strings::iterator & arg, const Strings::iterator & end) {
|
||||||
string arg = *i++;
|
Operation oldOp = op;
|
||||||
|
|
||||||
Operation oldOp = op;
|
if (*arg == "--help")
|
||||||
|
showManPage("nix-env");
|
||||||
|
else if (*arg == "--version")
|
||||||
|
printVersion("nix-env");
|
||||||
|
else if (*arg == "--install" || *arg == "-i")
|
||||||
|
op = opInstall;
|
||||||
|
else if (parseAutoArgs(arg, end, autoArgs_))
|
||||||
|
;
|
||||||
|
else if (parseSearchPathArg(arg, end, searchPath))
|
||||||
|
;
|
||||||
|
else if (*arg == "--force-name") // undocumented flag for nix-install-package
|
||||||
|
globals.forceName = getArg(*arg, arg, end);
|
||||||
|
else if (*arg == "--uninstall" || *arg == "-e")
|
||||||
|
op = opUninstall;
|
||||||
|
else if (*arg == "--upgrade" || *arg == "-u")
|
||||||
|
op = opUpgrade;
|
||||||
|
else if (*arg == "--set-flag")
|
||||||
|
op = opSetFlag;
|
||||||
|
else if (*arg == "--set")
|
||||||
|
op = opSet;
|
||||||
|
else if (*arg == "--query" || *arg == "-q")
|
||||||
|
op = opQuery;
|
||||||
|
else if (*arg == "--profile" || *arg == "-p")
|
||||||
|
globals.profile = absPath(getArg(*arg, arg, end));
|
||||||
|
else if (*arg == "--file" || *arg == "-f")
|
||||||
|
file = getArg(*arg, arg, end);
|
||||||
|
else if (*arg == "--switch-profile" || *arg == "-S")
|
||||||
|
op = opSwitchProfile;
|
||||||
|
else if (*arg == "--switch-generation" || *arg == "-G")
|
||||||
|
op = opSwitchGeneration;
|
||||||
|
else if (*arg == "--rollback")
|
||||||
|
op = opRollback;
|
||||||
|
else if (*arg == "--list-generations")
|
||||||
|
op = opListGenerations;
|
||||||
|
else if (*arg == "--delete-generations")
|
||||||
|
op = opDeleteGenerations;
|
||||||
|
else if (*arg == "--dry-run") {
|
||||||
|
printMsg(lvlInfo, "(dry run; not doing anything)");
|
||||||
|
globals.dryRun = true;
|
||||||
|
}
|
||||||
|
else if (*arg == "--system-filter")
|
||||||
|
globals.instSource.systemFilter = getArg(*arg, arg, end);
|
||||||
|
else if (*arg == "--prebuilt-only" || *arg == "-b")
|
||||||
|
globals.prebuiltOnly = true;
|
||||||
|
else if (*arg == "--repair")
|
||||||
|
repair = true;
|
||||||
|
else if (*arg != "" && arg->at(0) == '-') {
|
||||||
|
opFlags.push_back(*arg);
|
||||||
|
if (*arg == "--from-profile" || *arg == "--atr" || *arg == "-A") /* !!! hack */
|
||||||
|
opFlags.push_back(getArg(*arg, arg, end));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
opArgs.push_back(*arg);
|
||||||
|
|
||||||
if (arg == "--install" || arg == "-i")
|
if (oldOp && oldOp != op)
|
||||||
op = opInstall;
|
throw UsageError("only one operation may be specified");
|
||||||
else if (parseOptionArg(arg, i, args.end(),
|
|
||||||
globals.state, globals.instSource.autoArgs))
|
return true;
|
||||||
;
|
});
|
||||||
else if (arg == "--force-name") // undocumented flag for nix-install-package
|
|
||||||
globals.forceName = needArg(i, args, arg);
|
if (!op) throw UsageError("no operation specified");
|
||||||
else if (arg == "--uninstall" || arg == "-e")
|
|
||||||
op = opUninstall;
|
globals.state = std::shared_ptr<EvalState>(new EvalState(searchPath));
|
||||||
else if (arg == "--upgrade" || arg == "-u")
|
globals.state->repair = repair;
|
||||||
op = opUpgrade;
|
|
||||||
else if (arg == "--set-flag")
|
if (file != "")
|
||||||
op = opSetFlag;
|
globals.instSource.nixExprPath = lookupFileArg(*globals.state, file);
|
||||||
else if (arg == "--set")
|
|
||||||
op = opSet;
|
evalAutoArgs(*globals.state, autoArgs_, globals.instSource.autoArgs);
|
||||||
else if (arg == "--query" || arg == "-q")
|
|
||||||
op = opQuery;
|
if (globals.profile == "")
|
||||||
else if (arg == "--profile" || arg == "-p")
|
globals.profile = getEnv("NIX_PROFILE", "");
|
||||||
globals.profile = absPath(needArg(i, args, arg));
|
|
||||||
else if (arg == "--file" || arg == "-f")
|
if (globals.profile == "") {
|
||||||
globals.instSource.nixExprPath = lookupFileArg(globals.state, needArg(i, args, arg));
|
Path profileLink = getHomeDir() + "/.nix-profile";
|
||||||
else if (arg == "--switch-profile" || arg == "-S")
|
globals.profile = pathExists(profileLink)
|
||||||
op = opSwitchProfile;
|
? absPath(readLink(profileLink), dirOf(profileLink))
|
||||||
else if (arg == "--switch-generation" || arg == "-G")
|
: canonPath(settings.nixStateDir + "/profiles/default");
|
||||||
op = opSwitchGeneration;
|
|
||||||
else if (arg == "--rollback")
|
|
||||||
op = opRollback;
|
|
||||||
else if (arg == "--list-generations")
|
|
||||||
op = opListGenerations;
|
|
||||||
else if (arg == "--delete-generations")
|
|
||||||
op = opDeleteGenerations;
|
|
||||||
else if (arg == "--dry-run") {
|
|
||||||
printMsg(lvlInfo, "(dry run; not doing anything)");
|
|
||||||
globals.dryRun = true;
|
|
||||||
}
|
|
||||||
else if (arg == "--system-filter")
|
|
||||||
globals.instSource.systemFilter = needArg(i, args, arg);
|
|
||||||
else if (arg == "--prebuilt-only" || arg == "-b")
|
|
||||||
globals.prebuiltOnly = true;
|
|
||||||
else if (arg == "--repair")
|
|
||||||
globals.state.repair = true;
|
|
||||||
else {
|
|
||||||
remaining.push_back(arg);
|
|
||||||
if (arg[0] == '-') {
|
|
||||||
opFlags.push_back(arg);
|
|
||||||
if (arg == "--from-profile") { /* !!! hack */
|
|
||||||
if (i != args.end()) opFlags.push_back(*i++);
|
|
||||||
}
|
|
||||||
} else opArgs.push_back(arg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldOp && oldOp != op)
|
store = openStore();
|
||||||
throw UsageError("only one operation may be specified");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!op) throw UsageError("no operation specified");
|
op(globals, opFlags, opArgs);
|
||||||
|
|
||||||
if (globals.profile == "")
|
globals.state->printStats();
|
||||||
globals.profile = getEnv("NIX_PROFILE", "");
|
});
|
||||||
|
|
||||||
if (globals.profile == "") {
|
|
||||||
Path profileLink = getHomeDir() + "/.nix-profile";
|
|
||||||
globals.profile = pathExists(profileLink)
|
|
||||||
? absPath(readLink(profileLink), dirOf(profileLink))
|
|
||||||
: canonPath(settings.nixStateDir + "/profiles/default");
|
|
||||||
}
|
|
||||||
|
|
||||||
store = openStore();
|
|
||||||
|
|
||||||
op(globals, remaining, opFlags, opArgs);
|
|
||||||
|
|
||||||
globals.state.printStats();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
string programId = "nix-env";
|
|
||||||
|
|
|
@ -3,17 +3,10 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
using namespace nix;
|
using namespace nix;
|
||||||
|
|
||||||
|
|
||||||
void printHelp()
|
int main(int argc, char * * argv)
|
||||||
{
|
|
||||||
showManPage("nix-hash");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void run(Strings args)
|
|
||||||
{
|
{
|
||||||
HashType ht = htMD5;
|
HashType ht = htMD5;
|
||||||
bool flat = false;
|
bool flat = false;
|
||||||
|
@ -23,42 +16,48 @@ void run(Strings args)
|
||||||
|
|
||||||
Strings ss;
|
Strings ss;
|
||||||
|
|
||||||
for (Strings::iterator i = args.begin();
|
return handleExceptions(argv[0], [&]() {
|
||||||
i != args.end(); i++)
|
initNix();
|
||||||
{
|
|
||||||
if (*i == "--flat") flat = true;
|
|
||||||
else if (*i == "--base32") base32 = true;
|
|
||||||
else if (*i == "--truncate") truncate = true;
|
|
||||||
else if (*i == "--type") {
|
|
||||||
++i;
|
|
||||||
if (i == args.end()) throw UsageError("`--type' requires an argument");
|
|
||||||
ht = parseHashType(*i);
|
|
||||||
if (ht == htUnknown)
|
|
||||||
throw UsageError(format("unknown hash type `%1%'") % *i);
|
|
||||||
}
|
|
||||||
else if (*i == "--to-base16") op = opTo16;
|
|
||||||
else if (*i == "--to-base32") op = opTo32;
|
|
||||||
else ss.push_back(*i);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (op == opHash) {
|
parseCmdLine(argc, argv, [&](Strings::iterator & arg, const Strings::iterator & end) {
|
||||||
foreach (Strings::iterator, i, ss) {
|
if (*arg == "--help")
|
||||||
Hash h = flat ? hashFile(ht, *i) : hashPath(ht, *i).first;
|
showManPage("nix-hash");
|
||||||
if (truncate && h.hashSize > 20) h = compressHash(h, 20);
|
else if (*arg == "--version")
|
||||||
std::cout << format("%1%\n") %
|
printVersion("nix-hash");
|
||||||
(base32 ? printHash32(h) : printHash(h));
|
else if (*arg == "--flat") flat = true;
|
||||||
}
|
else if (*arg == "--base32") base32 = true;
|
||||||
}
|
else if (*arg == "--truncate") truncate = true;
|
||||||
|
else if (*arg == "--type") {
|
||||||
|
string s = getArg(*arg, arg, end);
|
||||||
|
ht = parseHashType(s);
|
||||||
|
if (ht == htUnknown)
|
||||||
|
throw UsageError(format("unknown hash type `%1%'") % s);
|
||||||
|
}
|
||||||
|
else if (*arg == "--to-base16") op = opTo16;
|
||||||
|
else if (*arg == "--to-base32") op = opTo32;
|
||||||
|
else if (*arg != "" && arg->at(0) == '-')
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
ss.push_back(*arg);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
else {
|
if (op == opHash) {
|
||||||
foreach (Strings::iterator, i, ss) {
|
for (auto & i : ss) {
|
||||||
Hash h = parseHash16or32(ht, *i);
|
Hash h = flat ? hashFile(ht, i) : hashPath(ht, i).first;
|
||||||
std::cout << format("%1%\n") %
|
if (truncate && h.hashSize > 20) h = compressHash(h, 20);
|
||||||
(op == opTo16 ? printHash(h) : printHash32(h));
|
std::cout << format("%1%\n") %
|
||||||
|
(base32 ? printHash32(h) : printHash(h));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
else {
|
||||||
|
for (auto & i : ss) {
|
||||||
|
Hash h = parseHash16or32(ht, i);
|
||||||
|
std::cout << format("%1%\n") %
|
||||||
|
(op == opTo16 ? printHash(h) : printHash32(h));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
string programId = "nix-hash";
|
|
||||||
|
|
||||||
|
|
|
@ -18,12 +18,6 @@
|
||||||
using namespace nix;
|
using namespace nix;
|
||||||
|
|
||||||
|
|
||||||
void printHelp()
|
|
||||||
{
|
|
||||||
showManPage("nix-instantiate");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static Expr * parseStdin(EvalState & state)
|
static Expr * parseStdin(EvalState & state)
|
||||||
{
|
{
|
||||||
startNest(nest, lvlTalkative, format("parsing standard input"));
|
startNest(nest, lvlTalkative, format("parsing standard input"));
|
||||||
|
@ -95,112 +89,108 @@ void processExpr(EvalState & state, const Strings & attrPaths,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void run(Strings args)
|
int main(int argc, char * * argv)
|
||||||
{
|
{
|
||||||
/* FIXME: hack. */
|
return handleExceptions(argv[0], [&]() {
|
||||||
Strings searchPath;
|
initNix();
|
||||||
Strings args2;
|
|
||||||
for (Strings::iterator i = args.begin(); i != args.end(); ) {
|
|
||||||
string arg = *i++;
|
|
||||||
if (!parseSearchPathArg(arg, i, args.end(), searchPath))
|
|
||||||
args2.push_back(arg);
|
|
||||||
}
|
|
||||||
args = args2;
|
|
||||||
|
|
||||||
EvalState state(searchPath);
|
Strings files, searchPath;
|
||||||
Strings files;
|
bool readStdin = false;
|
||||||
bool readStdin = false;
|
bool fromArgs = false;
|
||||||
bool fromArgs = false;
|
bool findFile = false;
|
||||||
bool findFile = false;
|
bool evalOnly = false;
|
||||||
bool evalOnly = false;
|
bool parseOnly = false;
|
||||||
bool parseOnly = false;
|
OutputKind outputKind = okPlain;
|
||||||
OutputKind outputKind = okPlain;
|
bool xmlOutputSourceLocation = true;
|
||||||
bool xmlOutputSourceLocation = true;
|
bool strict = false;
|
||||||
bool strict = false;
|
Strings attrPaths;
|
||||||
Strings attrPaths;
|
bool wantsReadWrite = false;
|
||||||
Bindings autoArgs;
|
std::map<string, string> autoArgs_;
|
||||||
bool wantsReadWrite = false;
|
bool repair = false;
|
||||||
|
|
||||||
for (Strings::iterator i = args.begin(); i != args.end(); ) {
|
parseCmdLine(argc, argv, [&](Strings::iterator & arg, const Strings::iterator & end) {
|
||||||
string arg = *i++;
|
if (*arg == "--help")
|
||||||
|
showManPage("nix-instantiate");
|
||||||
|
else if (*arg == "--version")
|
||||||
|
printVersion("nix-instantiate");
|
||||||
|
else if (*arg == "-")
|
||||||
|
readStdin = true;
|
||||||
|
else if (*arg == "--expr" || *arg == "-E")
|
||||||
|
fromArgs = true;
|
||||||
|
else if (*arg == "--eval" || *arg == "--eval-only")
|
||||||
|
evalOnly = true;
|
||||||
|
else if (*arg == "--read-write-mode")
|
||||||
|
wantsReadWrite = true;
|
||||||
|
else if (*arg == "--parse" || *arg == "--parse-only")
|
||||||
|
parseOnly = evalOnly = true;
|
||||||
|
else if (*arg == "--find-file")
|
||||||
|
findFile = true;
|
||||||
|
else if (*arg == "--attr" || *arg == "-A")
|
||||||
|
attrPaths.push_back(getArg(*arg, arg, end));
|
||||||
|
else if (parseAutoArgs(arg, end, autoArgs_))
|
||||||
|
;
|
||||||
|
else if (parseSearchPathArg(arg, end, searchPath))
|
||||||
|
;
|
||||||
|
else if (*arg == "--add-root")
|
||||||
|
gcRoot = getArg(*arg, arg, end);
|
||||||
|
else if (*arg == "--indirect")
|
||||||
|
indirectRoot = true;
|
||||||
|
else if (*arg == "--xml")
|
||||||
|
outputKind = okXML;
|
||||||
|
else if (*arg == "--json")
|
||||||
|
outputKind = okJSON;
|
||||||
|
else if (*arg == "--no-location")
|
||||||
|
xmlOutputSourceLocation = false;
|
||||||
|
else if (*arg == "--strict")
|
||||||
|
strict = true;
|
||||||
|
else if (*arg == "--repair")
|
||||||
|
repair = true;
|
||||||
|
else if (*arg == "--dry-run")
|
||||||
|
settings.readOnlyMode = true;
|
||||||
|
else if (*arg != "" && arg->at(0) == '-')
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
files.push_back(*arg);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
if (arg == "-")
|
EvalState state(searchPath);
|
||||||
readStdin = true;
|
state.repair = repair;
|
||||||
else if (arg == "--expr" || arg == "-E")
|
|
||||||
fromArgs = true;
|
Bindings autoArgs;
|
||||||
else if (arg == "--eval" || arg == "--eval-only")
|
evalAutoArgs(state, autoArgs_, autoArgs);
|
||||||
evalOnly = true;
|
|
||||||
else if (arg == "--read-write-mode")
|
if (evalOnly && !wantsReadWrite)
|
||||||
wantsReadWrite = true;
|
|
||||||
else if (arg == "--parse" || arg == "--parse-only")
|
|
||||||
parseOnly = evalOnly = true;
|
|
||||||
else if (arg == "--find-file")
|
|
||||||
findFile = true;
|
|
||||||
else if (arg == "--attr" || arg == "-A") {
|
|
||||||
if (i == args.end())
|
|
||||||
throw UsageError("`--attr' requires an argument");
|
|
||||||
attrPaths.push_back(*i++);
|
|
||||||
}
|
|
||||||
else if (parseOptionArg(arg, i, args.end(), state, autoArgs))
|
|
||||||
;
|
|
||||||
else if (arg == "--add-root") {
|
|
||||||
if (i == args.end())
|
|
||||||
throw UsageError("`--add-root' requires an argument");
|
|
||||||
gcRoot = absPath(*i++);
|
|
||||||
}
|
|
||||||
else if (arg == "--indirect")
|
|
||||||
indirectRoot = true;
|
|
||||||
else if (arg == "--xml")
|
|
||||||
outputKind = okXML;
|
|
||||||
else if (arg == "--json")
|
|
||||||
outputKind = okJSON;
|
|
||||||
else if (arg == "--no-location")
|
|
||||||
xmlOutputSourceLocation = false;
|
|
||||||
else if (arg == "--strict")
|
|
||||||
strict = true;
|
|
||||||
else if (arg == "--repair")
|
|
||||||
state.repair = true;
|
|
||||||
else if (arg == "--dry-run")
|
|
||||||
settings.readOnlyMode = true;
|
settings.readOnlyMode = true;
|
||||||
else if (arg[0] == '-')
|
|
||||||
throw UsageError(format("unknown flag `%1%'") % arg);
|
|
||||||
else
|
|
||||||
files.push_back(arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (evalOnly && !wantsReadWrite)
|
if (attrPaths.empty()) attrPaths.push_back("");
|
||||||
settings.readOnlyMode = true;
|
|
||||||
|
|
||||||
if (attrPaths.empty()) attrPaths.push_back("");
|
if (findFile) {
|
||||||
|
foreach (Strings::iterator, i, files) {
|
||||||
if (findFile) {
|
Path p = state.findFile(*i);
|
||||||
foreach (Strings::iterator, i, files) {
|
if (p == "") throw Error(format("unable to find `%1%'") % *i);
|
||||||
Path p = state.findFile(*i);
|
std::cout << p << std::endl;
|
||||||
if (p == "") throw Error(format("unable to find `%1%'") % *i);
|
}
|
||||||
std::cout << p << std::endl;
|
return;
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
store = openStore();
|
store = openStore();
|
||||||
|
|
||||||
if (readStdin) {
|
if (readStdin) {
|
||||||
Expr * e = parseStdin(state);
|
Expr * e = parseStdin(state);
|
||||||
processExpr(state, attrPaths, parseOnly, strict, autoArgs,
|
processExpr(state, attrPaths, parseOnly, strict, autoArgs,
|
||||||
evalOnly, outputKind, xmlOutputSourceLocation, e);
|
evalOnly, outputKind, xmlOutputSourceLocation, e);
|
||||||
} else if (files.empty() && !fromArgs)
|
} else if (files.empty() && !fromArgs)
|
||||||
files.push_back("./default.nix");
|
files.push_back("./default.nix");
|
||||||
|
|
||||||
foreach (Strings::iterator, i, files) {
|
foreach (Strings::iterator, i, files) {
|
||||||
Expr * e = fromArgs
|
Expr * e = fromArgs
|
||||||
? state.parseExprFromString(*i, absPath("."))
|
? state.parseExprFromString(*i, absPath("."))
|
||||||
: state.parseExprFromFile(resolveExprPath(lookupFileArg(state, *i)));
|
: state.parseExprFromFile(resolveExprPath(lookupFileArg(state, *i)));
|
||||||
processExpr(state, attrPaths, parseOnly, strict, autoArgs,
|
processExpr(state, attrPaths, parseOnly, strict, autoArgs,
|
||||||
evalOnly, outputKind, xmlOutputSourceLocation, e);
|
evalOnly, outputKind, xmlOutputSourceLocation, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
state.printStats();
|
state.printStats();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
string programId = "nix-instantiate";
|
|
||||||
|
|
|
@ -29,12 +29,6 @@ using std::cout;
|
||||||
typedef void (* Operation) (Strings opFlags, Strings opArgs);
|
typedef void (* Operation) (Strings opFlags, Strings opArgs);
|
||||||
|
|
||||||
|
|
||||||
void printHelp()
|
|
||||||
{
|
|
||||||
showManPage("nix-store");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static Path gcRoot;
|
static Path gcRoot;
|
||||||
static int rootNr = 0;
|
static int rootNr = 0;
|
||||||
static bool indirectRoot = false;
|
static bool indirectRoot = false;
|
||||||
|
@ -782,7 +776,7 @@ static void opVerify(Strings opFlags, Strings opArgs)
|
||||||
|
|
||||||
if (ensureLocalStore().verifyStore(checkContents, repair)) {
|
if (ensureLocalStore().verifyStore(checkContents, repair)) {
|
||||||
printMsg(lvlError, "warning: not all errors were fixed");
|
printMsg(lvlError, "warning: not all errors were fixed");
|
||||||
exitCode = 1;
|
throw Exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -793,6 +787,8 @@ static void opVerifyPath(Strings opFlags, Strings opArgs)
|
||||||
if (!opFlags.empty())
|
if (!opFlags.empty())
|
||||||
throw UsageError("no flags expected");
|
throw UsageError("no flags expected");
|
||||||
|
|
||||||
|
int status = 0;
|
||||||
|
|
||||||
foreach (Strings::iterator, i, opArgs) {
|
foreach (Strings::iterator, i, opArgs) {
|
||||||
Path path = followLinksToStorePath(*i);
|
Path path = followLinksToStorePath(*i);
|
||||||
printMsg(lvlTalkative, format("checking path `%1%'...") % path);
|
printMsg(lvlTalkative, format("checking path `%1%'...") % path);
|
||||||
|
@ -802,9 +798,11 @@ static void opVerifyPath(Strings opFlags, Strings opArgs)
|
||||||
printMsg(lvlError,
|
printMsg(lvlError,
|
||||||
format("path `%1%' was modified! expected hash `%2%', got `%3%'")
|
format("path `%1%' was modified! expected hash `%2%', got `%3%'")
|
||||||
% path % printHash(info.hash) % printHash(current.first));
|
% path % printHash(info.hash) % printHash(current.first));
|
||||||
exitCode = 1;
|
status = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw Exit(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1017,95 +1015,96 @@ static void opServe(Strings opFlags, Strings opArgs)
|
||||||
/* Scan the arguments; find the operation, set global flags, put all
|
/* Scan the arguments; find the operation, set global flags, put all
|
||||||
other flags in a list, and put all other arguments in another
|
other flags in a list, and put all other arguments in another
|
||||||
list. */
|
list. */
|
||||||
void run(Strings args)
|
int main(int argc, char * * argv)
|
||||||
{
|
{
|
||||||
Strings opFlags, opArgs;
|
return handleExceptions(argv[0], [&]() {
|
||||||
Operation op = 0;
|
initNix();
|
||||||
|
|
||||||
for (Strings::iterator i = args.begin(); i != args.end(); ) {
|
Strings opFlags, opArgs;
|
||||||
string arg = *i++;
|
Operation op = 0;
|
||||||
|
|
||||||
Operation oldOp = op;
|
parseCmdLine(argc, argv, [&](Strings::iterator & arg, const Strings::iterator & end) {
|
||||||
|
Operation oldOp = op;
|
||||||
|
|
||||||
if (arg == "--realise" || arg == "--realize" || arg == "-r")
|
if (*arg == "--help")
|
||||||
op = opRealise;
|
showManPage("nix-store");
|
||||||
else if (arg == "--add" || arg == "-A")
|
else if (*arg == "--version")
|
||||||
op = opAdd;
|
printVersion("nix-store");
|
||||||
else if (arg == "--add-fixed")
|
else if (*arg == "--realise" || *arg == "--realize" || *arg == "-r")
|
||||||
op = opAddFixed;
|
op = opRealise;
|
||||||
else if (arg == "--print-fixed-path")
|
else if (*arg == "--add" || *arg == "-A")
|
||||||
op = opPrintFixedPath;
|
op = opAdd;
|
||||||
else if (arg == "--delete")
|
else if (*arg == "--add-fixed")
|
||||||
op = opDelete;
|
op = opAddFixed;
|
||||||
else if (arg == "--query" || arg == "-q")
|
else if (*arg == "--print-fixed-path")
|
||||||
op = opQuery;
|
op = opPrintFixedPath;
|
||||||
else if (arg == "--print-env")
|
else if (*arg == "--delete")
|
||||||
op = opPrintEnv;
|
op = opDelete;
|
||||||
else if (arg == "--read-log" || arg == "-l")
|
else if (*arg == "--query" || *arg == "-q")
|
||||||
op = opReadLog;
|
op = opQuery;
|
||||||
else if (arg == "--dump-db")
|
else if (*arg == "--print-env")
|
||||||
op = opDumpDB;
|
op = opPrintEnv;
|
||||||
else if (arg == "--load-db")
|
else if (*arg == "--read-log" || *arg == "-l")
|
||||||
op = opLoadDB;
|
op = opReadLog;
|
||||||
else if (arg == "--register-validity")
|
else if (*arg == "--dump-db")
|
||||||
op = opRegisterValidity;
|
op = opDumpDB;
|
||||||
else if (arg == "--check-validity")
|
else if (*arg == "--load-db")
|
||||||
op = opCheckValidity;
|
op = opLoadDB;
|
||||||
else if (arg == "--gc")
|
else if (*arg == "--register-validity")
|
||||||
op = opGC;
|
op = opRegisterValidity;
|
||||||
else if (arg == "--dump")
|
else if (*arg == "--check-validity")
|
||||||
op = opDump;
|
op = opCheckValidity;
|
||||||
else if (arg == "--restore")
|
else if (*arg == "--gc")
|
||||||
op = opRestore;
|
op = opGC;
|
||||||
else if (arg == "--export")
|
else if (*arg == "--dump")
|
||||||
op = opExport;
|
op = opDump;
|
||||||
else if (arg == "--import")
|
else if (*arg == "--restore")
|
||||||
op = opImport;
|
op = opRestore;
|
||||||
else if (arg == "--init")
|
else if (*arg == "--export")
|
||||||
op = opInit;
|
op = opExport;
|
||||||
else if (arg == "--verify")
|
else if (*arg == "--import")
|
||||||
op = opVerify;
|
op = opImport;
|
||||||
else if (arg == "--verify-path")
|
else if (*arg == "--init")
|
||||||
op = opVerifyPath;
|
op = opInit;
|
||||||
else if (arg == "--repair-path")
|
else if (*arg == "--verify")
|
||||||
op = opRepairPath;
|
op = opVerify;
|
||||||
else if (arg == "--optimise" || arg == "--optimize")
|
else if (*arg == "--verify-path")
|
||||||
op = opOptimise;
|
op = opVerifyPath;
|
||||||
else if (arg == "--query-failed-paths")
|
else if (*arg == "--repair-path")
|
||||||
op = opQueryFailedPaths;
|
op = opRepairPath;
|
||||||
else if (arg == "--clear-failed-paths")
|
else if (*arg == "--optimise" || *arg == "--optimize")
|
||||||
op = opClearFailedPaths;
|
op = opOptimise;
|
||||||
else if (arg == "--add-root") {
|
else if (*arg == "--query-failed-paths")
|
||||||
if (i == args.end())
|
op = opQueryFailedPaths;
|
||||||
throw UsageError("`--add-root requires an argument");
|
else if (*arg == "--clear-failed-paths")
|
||||||
gcRoot = absPath(*i++);
|
op = opClearFailedPaths;
|
||||||
}
|
else if (*arg == "--add-root")
|
||||||
else if (arg == "--indirect")
|
gcRoot = absPath(getArg(*arg, arg, end));
|
||||||
indirectRoot = true;
|
else if (*arg == "--indirect")
|
||||||
else if (arg == "--no-output")
|
indirectRoot = true;
|
||||||
noOutput = true;
|
else if (*arg == "--no-output")
|
||||||
else if (arg == "--serve")
|
noOutput = true;
|
||||||
op = opServe;
|
else if (*arg == "--serve")
|
||||||
else if (arg[0] == '-') {
|
op = opServe;
|
||||||
opFlags.push_back(arg);
|
else if (*arg != "" && arg->at(0) == '-') {
|
||||||
if (arg == "--max-freed" || arg == "--max-links" || arg == "--max-atime") { /* !!! hack */
|
opFlags.push_back(*arg);
|
||||||
if (i != args.end()) opFlags.push_back(*i++);
|
if (*arg == "--max-freed" || *arg == "--max-links" || *arg == "--max-atime") /* !!! hack */
|
||||||
|
opFlags.push_back(getArg(*arg, arg, end));
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else
|
opArgs.push_back(*arg);
|
||||||
opArgs.push_back(arg);
|
|
||||||
|
|
||||||
if (oldOp && oldOp != op)
|
if (oldOp && oldOp != op)
|
||||||
throw UsageError("only one operation may be specified");
|
throw UsageError("only one operation may be specified");
|
||||||
}
|
|
||||||
|
|
||||||
if (!op) throw UsageError("no operation specified");
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
if (op != opDump && op != opRestore) /* !!! hack */
|
if (!op) throw UsageError("no operation specified");
|
||||||
store = openStore(op != opGC);
|
|
||||||
|
|
||||||
op(opFlags, opArgs);
|
if (op != opDump && op != opRestore) /* !!! hack */
|
||||||
|
store = openStore(op != opGC);
|
||||||
|
|
||||||
|
op(opFlags, opArgs);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
string programId = "nix-store";
|
|
||||||
|
|
Loading…
Reference in a new issue