about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libmain/shared.cc39
-rw-r--r--src/libmain/shared.hh9
-rw-r--r--src/nix-env/Makefile.am5
-rw-r--r--src/nix-env/help.txt31
-rw-r--r--src/nix-env/main.cc11
-rw-r--r--src/nix-hash/Makefile.am5
-rw-r--r--src/nix-hash/help.txt6
-rw-r--r--src/nix-hash/nix-hash.cc7
-rw-r--r--src/nix-instantiate/Makefile.am5
-rw-r--r--src/nix-instantiate/help.txt15
-rw-r--r--src/nix-instantiate/main.cc11
-rw-r--r--src/nix-store/Makefile.am2
-rw-r--r--src/nix-store/main.cc10
13 files changed, 125 insertions, 31 deletions
diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc
index 632794db3d8d..b99a74bb4027 100644
--- a/src/libmain/shared.cc
+++ b/src/libmain/shared.cc
@@ -23,31 +23,42 @@ static void initAndRun(int argc, char * * argv)
     nixDBPath = (string) NIX_STATE_DIR + "/db";
 
     /* Put the arguments in a vector. */
-    Strings args;
+    Strings args, remaining;
     while (argc--) args.push_back(*argv++);
     args.erase(args.begin());
     
     /* Expand compound dash options (i.e., `-qlf' -> `-q -l -f'), and
        ignore options for the ATerm library. */
-    for (Strings::iterator it = args.begin();
-         it != args.end(); )
-    {
-        string arg = *it;
-        if (string(arg, 0, 4) == "-at-")
-            it = args.erase(it);
+    for (Strings::iterator i = args.begin(); i != args.end(); ++i) {
+        string arg = *i;
+        if (string(arg, 0, 4) == "-at-") ;
         else if (arg.length() > 2 && arg[0] == '-' && arg[1] != '-') {
-            for (unsigned int i = 1; i < arg.length(); i++)
-                if (isalpha(arg[i]))
-                    args.insert(it, (string) "-" + arg[i]);
+            for (unsigned int j = 1; j < arg.length(); j++)
+                if (isalpha(arg[j]))
+                    remaining.push_back((string) "-" + arg[j]);
                 else {
-                    args.insert(it, string(arg, i));
+                    remaining.push_back(string(arg, j));
                     break;
                 }
-            it = args.erase(it);
-        } else it++;
+        } else remaining.push_back(arg);
     }
+    args = remaining;
+    remaining.clear();
 
-    run(args);
+    /* 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(remaining);
 }
 
 
diff --git a/src/libmain/shared.hh b/src/libmain/shared.hh
index 8ea637fd21ac..76b639e3785d 100644
--- a/src/libmain/shared.hh
+++ b/src/libmain/shared.hh
@@ -6,8 +6,17 @@
 #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);
 
+/* Should print a help message to stdout and return. */
+void printHelp();
+
 
 extern string programId;
 
diff --git a/src/nix-env/Makefile.am b/src/nix-env/Makefile.am
index add54581b051..32e7a8111ebc 100644
--- a/src/nix-env/Makefile.am
+++ b/src/nix-env/Makefile.am
@@ -6,6 +6,11 @@ nix_env_LDADD = ../libmain/libmain.a ../libexpr/libexpr.a \
  ../boost/format/libformat.a -L../../externals/inst/lib -ldb_cxx \
  -lsglr -lATB -lconversion -lasfix2 -lmept -lATerm
 
+main.o: help.txt.hh
+
+%.txt.hh: %.txt
+	../bin2c/bin2c helpText < $< > $@ || (rm $@ && exit 1)
+
 AM_CXXFLAGS = \
  -I.. -I../../externals/inst/include -I../libutil -I../libstore \
  -I../libexpr -I../libmain
diff --git a/src/nix-env/help.txt b/src/nix-env/help.txt
new file mode 100644
index 000000000000..69c4742944fd
--- /dev/null
+++ b/src/nix-env/help.txt
@@ -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
diff --git a/src/nix-env/main.cc b/src/nix-env/main.cc
index 3c72a7950727..829e2f4ae508 100644
--- a/src/nix-env/main.cc
+++ b/src/nix-env/main.cc
@@ -3,6 +3,7 @@
 #include "shared.hh"
 #include "parser.hh"
 #include "eval.hh"
+#include "help.txt.hh"
 
 
 typedef void (* Operation) (EvalState & state,
@@ -20,6 +21,12 @@ struct DrvInfo
 typedef map<Path, DrvInfo> DrvInfos;
 
 
+void printHelp()
+{
+    cout << string((char *) helpText, sizeof helpText);
+}
+
+
 bool parseDerivation(EvalState & state, Expr e, DrvInfo & drv)
 {
     ATMatcher m;
@@ -395,10 +402,6 @@ void run(Strings args)
             op = opUninstall;
         else if (arg == "--query" || arg == "-q")
             op = opQuery;
-        else if (arg == "--verbose" || arg == "-v")
-            verbosity = (Verbosity) ((int) verbosity + 1);
-        else if (arg[0] == '-')
-            opFlags.push_back(arg);
         else
             opArgs.push_back(arg);
 
diff --git a/src/nix-hash/Makefile.am b/src/nix-hash/Makefile.am
index 8609cb216453..154f7a2760d2 100644
--- a/src/nix-hash/Makefile.am
+++ b/src/nix-hash/Makefile.am
@@ -4,5 +4,10 @@ nix_hash_SOURCES = nix-hash.cc
 nix_hash_LDADD = ../libmain/libmain.a ../libstore/libstore.a ../libutil/libutil.a \
  ../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 = \
  -I.. -I../../externals/inst/include -I../libutil -I../libstore -I../libmain
diff --git a/src/nix-hash/help.txt b/src/nix-hash/help.txt
new file mode 100644
index 000000000000..84ba152c5adc
--- /dev/null
+++ b/src/nix-hash/help.txt
@@ -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
diff --git a/src/nix-hash/nix-hash.cc b/src/nix-hash/nix-hash.cc
index 77c169b9a952..23309ff7469e 100644
--- a/src/nix-hash/nix-hash.cc
+++ b/src/nix-hash/nix-hash.cc
@@ -2,6 +2,13 @@
 
 #include "hash.hh"
 #include "shared.hh"
+#include "help.txt.hh"
+
+
+void printHelp()
+{
+    cout << string((char *) helpText, sizeof helpText);
+}
 
 
 void run(Strings args)
diff --git a/src/nix-instantiate/Makefile.am b/src/nix-instantiate/Makefile.am
index 91843f66341b..7a04e932eb51 100644
--- a/src/nix-instantiate/Makefile.am
+++ b/src/nix-instantiate/Makefile.am
@@ -6,6 +6,11 @@ nix_instantiate_LDADD = ../libmain/libmain.a ../libexpr/libexpr.a \
  ../boost/format/libformat.a -L../../externals/inst/lib -ldb_cxx \
  -lsglr -lATB -lconversion -lasfix2 -lmept -lATerm
 
+main.o: help.txt.hh
+
+%.txt.hh: %.txt
+	../bin2c/bin2c helpText < $< > $@ || (rm $@ && exit 1)
+
 AM_CXXFLAGS = \
  -I.. -I../../externals/inst/include -I../libutil -I../libstore \
  -I../libexpr -I../libmain
diff --git a/src/nix-instantiate/help.txt b/src/nix-instantiate/help.txt
new file mode 100644
index 000000000000..fbe9d92dbfea
--- /dev/null
+++ b/src/nix-instantiate/help.txt
@@ -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)
diff --git a/src/nix-instantiate/main.cc b/src/nix-instantiate/main.cc
index 50a4991a53a8..305c3b551ca5 100644
--- a/src/nix-instantiate/main.cc
+++ b/src/nix-instantiate/main.cc
@@ -6,6 +6,13 @@
 #include "shared.hh"
 #include "eval.hh"
 #include "parser.hh"
+#include "help.txt.hh"
+
+
+void printHelp()
+{
+    cout << string((char *) helpText, sizeof helpText);
+}
 
 
 #if 0
@@ -87,9 +94,7 @@ void run(Strings args)
         }
         else
 #endif
-        if (arg == "--verbose" || arg == "-v")
-            verbosity = (Verbosity) ((int) verbosity + 1);
-        else if (arg == "-")
+        if (arg == "-")
             readStdin = true;
         else if (arg[0] == '-')
             throw UsageError(format("unknown flag `%1%`") % arg);
diff --git a/src/nix-store/Makefile.am b/src/nix-store/Makefile.am
index 3738c53ca2f0..80e5987429d9 100644
--- a/src/nix-store/Makefile.am
+++ b/src/nix-store/Makefile.am
@@ -6,7 +6,7 @@ nix_store_LDADD = ../libmain/libmain.a ../libstore/libstore.a ../libutil/libutil
 
 main.o: help.txt.hh
 
-%.hh: %
+%.txt.hh: %.txt
 	../bin2c/bin2c helpText < $< > $@ || (rm $@ && exit 1)
 
 AM_CXXFLAGS = \
diff --git a/src/nix-store/main.cc b/src/nix-store/main.cc
index c73de52896fb..48752c2bf59b 100644
--- a/src/nix-store/main.cc
+++ b/src/nix-store/main.cc
@@ -12,14 +12,12 @@
 typedef void (* Operation) (Strings opFlags, Strings opArgs);
 
 
-static void printHelp()
+void printHelp()
 {
     cout << string((char *) helpText, sizeof helpText);
-    exit(0);
 }
 
 
-
 static Path checkPath(const Path & arg)
 {
     return arg; /* !!! check that arg is in the store */
@@ -276,12 +274,6 @@ void run(Strings args)
             op = opInit;
         else if (arg == "--verify")
             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] == '-')
             opFlags.push_back(arg);
         else