* Allow arguments to be passed to programs in `nix run'.

This commit is contained in:
Eelco Dolstra 2003-03-28 09:53:22 +00:00
parent 0f40a560ca
commit f915f77349
2 changed files with 28 additions and 26 deletions

View file

@ -393,7 +393,7 @@ string getPkg(string hash)
} }
void runPkg(string hash) void runPkg(string hash, const vector<string> & args)
{ {
string src; string src;
string path; string path;
@ -424,8 +424,17 @@ void runPkg(string hash)
putenv((char *) s->c_str()); putenv((char *) s->c_str());
} }
/* Create the list of arguments. */
const char * args2[env.size() + 2];
int i = 0;
args2[i++] = runner.c_str();
for (vector<string>::const_iterator it = args.begin();
it != args.end(); it++, i++)
args2[i] = it->c_str();
args2[i] = 0;
/* Execute the runner. This should not return. */ /* Execute the runner. This should not return. */
execl(runner.c_str(), runner.c_str(), 0); execv(runner.c_str(), (char * *) args2);
cout << strerror(errno) << endl; cout << strerror(errno) << endl;
@ -657,8 +666,8 @@ void run(vector<string> args)
string path = getPkg(args[0]); string path = getPkg(args[0]);
cout << path << endl; cout << path << endl;
} else if (cmd == "run") { } else if (cmd == "run") {
if (args.size() != 1) throw argcError; if (args.size() < 1) throw argcError;
runPkg(args[0]); runPkg(args[0], vector<string>(args.begin() + 1, args.end()));
} else if (cmd == "ensure") { } else if (cmd == "ensure") {
if (args.size() != 1) throw argcError; if (args.size() != 1) throw argcError;
ensurePkg(args[0]); ensurePkg(args[0]);
@ -708,8 +717,8 @@ Subcommands:
listinst listinst
Prints a list of installed packages. Prints a list of installed packages.
run HASH run HASH ARGS...
Run the descriptor referenced by HASH. Run the descriptor referenced by HASH with the given arguments.
ensure HASH ensure HASH
Like getpkg, but if HASH refers to a run descriptor, fetch only Like getpkg, but if HASH refers to a run descriptor, fetch only
@ -730,8 +739,6 @@ Subcommands:
void main2(int argc, char * * argv) void main2(int argc, char * * argv)
{ {
int c;
umask(0022); umask(0022);
if (getenv(PKGINFO_ENVVAR)) if (getenv(PKGINFO_ENVVAR))
@ -740,28 +747,23 @@ void main2(int argc, char * * argv)
if (getenv(PKGHOME_ENVVAR)) if (getenv(PKGHOME_ENVVAR))
pkgHome = getenv(PKGHOME_ENVVAR); pkgHome = getenv(PKGHOME_ENVVAR);
opterr = 0; /* Parse the global flags. */
while (argc) {
while ((c = getopt(argc, argv, "hd:")) != EOF) { string arg(*argv);
cout << arg << endl;
switch (c) { if (arg == "-h" || arg == "--help") {
case 'h':
printUsage(); printUsage();
return; return;
} else if (arg == "-d") {
case 'd':
dbfile = optarg; dbfile = optarg;
break; } else if (arg[0] == '-') {
throw UsageError("invalid option `" + arg + "'");
default: } else break;
throw UsageError("invalid option `" + string(1, optopt) + "'"); argv++, argc--;
break;
}
} }
/* Put the remainder in a vector and pass it to run2(). */
vector<string> args; vector<string> args;
argc--, argv++;
while (argc--) args.push_back(*argv++); while (argc--) args.push_back(*argv++);
run(args); run(args);
} }
@ -769,7 +771,7 @@ void main2(int argc, char * * argv)
int main(int argc, char * * argv) int main(int argc, char * * argv)
{ {
prog = argv[0]; prog = *argv++, argc--;
try { try {
try { try {

View file

@ -4,4 +4,4 @@ export LD_LIBRARY_PATH=$glib/lib:$atk/lib:$pango/lib:$gtk/lib:$gnet/lib:$pspell/
ldd $pan/bin/pan ldd $pan/bin/pan
$pan/bin/pan $pan/bin/pan $*