* Help text for all (non-script) programs, so no more:

$ nix-instantiate --help
error: unknown flag `--help`
Try `nix-instantiate --help' for more information.

:-)
This commit is contained in:
Eelco Dolstra 2003-12-01 15:55:05 +00:00
parent 905d5b91fa
commit 078e20885e
14 changed files with 126 additions and 32 deletions

View file

@ -23,31 +23,42 @@ static void initAndRun(int argc, char * * argv)
nixDBPath = (string) NIX_STATE_DIR + "/db"; nixDBPath = (string) NIX_STATE_DIR + "/db";
/* Put the arguments in a vector. */ /* Put the arguments in a vector. */
Strings args; Strings args, remaining;
while (argc--) args.push_back(*argv++); while (argc--) args.push_back(*argv++);
args.erase(args.begin()); args.erase(args.begin());
/* Expand compound dash options (i.e., `-qlf' -> `-q -l -f'), and /* Expand compound dash options (i.e., `-qlf' -> `-q -l -f'), and
ignore options for the ATerm library. */ ignore options for the ATerm library. */
for (Strings::iterator it = args.begin(); for (Strings::iterator i = args.begin(); i != args.end(); ++i) {
it != args.end(); ) string arg = *i;
{ if (string(arg, 0, 4) == "-at-") ;
string arg = *it;
if (string(arg, 0, 4) == "-at-")
it = args.erase(it);
else if (arg.length() > 2 && arg[0] == '-' && arg[1] != '-') { else if (arg.length() > 2 && arg[0] == '-' && arg[1] != '-') {
for (unsigned int i = 1; i < arg.length(); i++) for (unsigned int j = 1; j < arg.length(); j++)
if (isalpha(arg[i])) if (isalpha(arg[j]))
args.insert(it, (string) "-" + arg[i]); remaining.push_back((string) "-" + arg[j]);
else { else {
args.insert(it, string(arg, i)); remaining.push_back(string(arg, j));
break; break;
} }
it = args.erase(it); } else remaining.push_back(arg);
} else it++; }
args = remaining;
remaining.clear();
/* Process default options. */
for (Strings::iterator i = args.begin(); i != args.end(); ++i) {
string arg = *i;
if (arg == "--verbose" || arg == "-v")
verbosity = (Verbosity) ((int) verbosity + 1);
else if (arg == "--help") {
printHelp();
return;
} else if (arg == "--keep-failed" || arg == "-K")
keepFailed = true;
else remaining.push_back(arg);
} }
run(args); run(remaining);
} }

View file

@ -6,8 +6,17 @@
#include "util.hh" #include "util.hh"
/* 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(Strings args); void run(Strings args);
/* Should print a help message to stdout and return. */
void printHelp();
extern string programId; extern string programId;

View file

@ -6,6 +6,11 @@ nix_env_LDADD = ../libmain/libmain.a ../libexpr/libexpr.a \
../boost/format/libformat.a -L../../externals/inst/lib -ldb_cxx \ ../boost/format/libformat.a -L../../externals/inst/lib -ldb_cxx \
-lsglr -lATB -lconversion -lasfix2 -lmept -lATerm -lsglr -lATB -lconversion -lasfix2 -lmept -lATerm
main.o: help.txt.hh
%.txt.hh: %.txt
../bin2c/bin2c helpText < $< > $@ || (rm $@ && exit 1)
AM_CXXFLAGS = \ AM_CXXFLAGS = \
-I.. -I../../externals/inst/include -I../libutil -I../libstore \ -I.. -I../../externals/inst/include -I../libutil -I../libstore \
-I../libexpr -I../libmain -I../libexpr -I../libmain

31
src/nix-env/help.txt Normal file
View file

@ -0,0 +1,31 @@
nix-env [OPTIONS...] [ARGUMENTS...]
`nix-env' is a tool to manipulate Nix user environments.
Operations:
--install / -i FILE: add a derivation to the user environment
--uninstall / -u: remove a derivation to the user environment
--query / -q: perform a query on an environment or Nix expression
The previous operations take a list of derivation names. The special
name `*' may be used to indicate all derivations.
--version: output version information
--help: display help
Query types:
--name: print derivation names (default)
--expr / -e: print derivation store expression
--status / -s: print installed/present status
Query sources:
--installed: use installed derivations (default)
--available / -f FILE: use derivations available in expression FILE
Options:
--verbose / -v: verbose operation (may be repeated)
--keep-failed / -K: keep temporary directories of failed builds

View file

@ -3,6 +3,7 @@
#include "shared.hh" #include "shared.hh"
#include "parser.hh" #include "parser.hh"
#include "eval.hh" #include "eval.hh"
#include "help.txt.hh"
typedef void (* Operation) (EvalState & state, typedef void (* Operation) (EvalState & state,
@ -20,6 +21,12 @@ struct DrvInfo
typedef map<Path, DrvInfo> DrvInfos; typedef map<Path, DrvInfo> DrvInfos;
void printHelp()
{
cout << string((char *) helpText, sizeof helpText);
}
bool parseDerivation(EvalState & state, Expr e, DrvInfo & drv) bool parseDerivation(EvalState & state, Expr e, DrvInfo & drv)
{ {
ATMatcher m; ATMatcher m;
@ -395,10 +402,6 @@ void run(Strings args)
op = opUninstall; op = opUninstall;
else if (arg == "--query" || arg == "-q") else if (arg == "--query" || arg == "-q")
op = opQuery; op = opQuery;
else if (arg == "--verbose" || arg == "-v")
verbosity = (Verbosity) ((int) verbosity + 1);
else if (arg[0] == '-')
opFlags.push_back(arg);
else else
opArgs.push_back(arg); opArgs.push_back(arg);

View file

@ -4,5 +4,10 @@ nix_hash_SOURCES = nix-hash.cc
nix_hash_LDADD = ../libmain/libmain.a ../libstore/libstore.a ../libutil/libutil.a \ nix_hash_LDADD = ../libmain/libmain.a ../libstore/libstore.a ../libutil/libutil.a \
../boost/format/libformat.a -L../../externals/inst/lib -ldb_cxx -lATerm ../boost/format/libformat.a -L../../externals/inst/lib -ldb_cxx -lATerm
nix-hash.o: help.txt.hh
%.txt.hh: %.txt
../bin2c/bin2c helpText < $< > $@ || (rm $@ && exit 1)
AM_CXXFLAGS = \ AM_CXXFLAGS = \
-I.. -I../../externals/inst/include -I../libutil -I../libstore -I../libmain -I.. -I../../externals/inst/include -I../libutil -I../libstore -I../libmain

6
src/nix-hash/help.txt Normal file
View file

@ -0,0 +1,6 @@
nix-hash [OPTIONS...] [FILES...]
`nix-hash computes and prints cryptographic hashes for the specified
files.
--flat: compute hash of regular file contents, not metadata

View file

@ -2,6 +2,13 @@
#include "hash.hh" #include "hash.hh"
#include "shared.hh" #include "shared.hh"
#include "help.txt.hh"
void printHelp()
{
cout << string((char *) helpText, sizeof helpText);
}
void run(Strings args) void run(Strings args)

View file

@ -6,6 +6,11 @@ nix_instantiate_LDADD = ../libmain/libmain.a ../libexpr/libexpr.a \
../boost/format/libformat.a -L../../externals/inst/lib -ldb_cxx \ ../boost/format/libformat.a -L../../externals/inst/lib -ldb_cxx \
-lsglr -lATB -lconversion -lasfix2 -lmept -lATerm -lsglr -lATB -lconversion -lasfix2 -lmept -lATerm
main.o: help.txt.hh
%.txt.hh: %.txt
../bin2c/bin2c helpText < $< > $@ || (rm $@ && exit 1)
AM_CXXFLAGS = \ AM_CXXFLAGS = \
-I.. -I../../externals/inst/include -I../libutil -I../libstore \ -I.. -I../../externals/inst/include -I../libutil -I../libstore \
-I../libexpr -I../libmain -I../libexpr -I../libmain

View file

@ -0,0 +1,15 @@
nix-instantiate [OPTIONS...] [FILES...]
`nix-instantiate' turns Nix expressions into store expressions.
The argument `-' may be specified to read a Nix expression from
standard input.
Options:
--version: output version information
--help: display help
Options:
--verbose / -v: verbose operation (may be repeated)

View file

@ -6,6 +6,13 @@
#include "shared.hh" #include "shared.hh"
#include "eval.hh" #include "eval.hh"
#include "parser.hh" #include "parser.hh"
#include "help.txt.hh"
void printHelp()
{
cout << string((char *) helpText, sizeof helpText);
}
#if 0 #if 0
@ -87,9 +94,7 @@ void run(Strings args)
} }
else else
#endif #endif
if (arg == "--verbose" || arg == "-v") if (arg == "-")
verbosity = (Verbosity) ((int) verbosity + 1);
else if (arg == "-")
readStdin = true; readStdin = true;
else if (arg[0] == '-') else if (arg[0] == '-')
throw UsageError(format("unknown flag `%1%`") % arg); throw UsageError(format("unknown flag `%1%`") % arg);

View file

@ -6,7 +6,7 @@ nix_store_LDADD = ../libmain/libmain.a ../libstore/libstore.a ../libutil/libutil
main.o: help.txt.hh main.o: help.txt.hh
%.hh: % %.txt.hh: %.txt
../bin2c/bin2c helpText < $< > $@ || (rm $@ && exit 1) ../bin2c/bin2c helpText < $< > $@ || (rm $@ && exit 1)
AM_CXXFLAGS = \ AM_CXXFLAGS = \

View file

@ -12,14 +12,12 @@
typedef void (* Operation) (Strings opFlags, Strings opArgs); typedef void (* Operation) (Strings opFlags, Strings opArgs);
static void printHelp() void printHelp()
{ {
cout << string((char *) helpText, sizeof helpText); cout << string((char *) helpText, sizeof helpText);
exit(0);
} }
static Path checkPath(const Path & arg) static Path checkPath(const Path & arg)
{ {
return arg; /* !!! check that arg is in the store */ return arg; /* !!! check that arg is in the store */
@ -276,12 +274,6 @@ void run(Strings args)
op = opInit; op = opInit;
else if (arg == "--verify") else if (arg == "--verify")
op = opVerify; op = opVerify;
else if (arg == "--verbose" || arg == "-v")
verbosity = (Verbosity) ((int) verbosity + 1);
else if (arg == "--keep-failed" || arg == "-K")
keepFailed = true;
else if (arg == "--help")
printHelp();
else if (arg[0] == '-') else if (arg[0] == '-')
opFlags.push_back(arg); opFlags.push_back(arg);
else else