diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2004-02-06T16·03+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2004-02-06T16·03+0000 |
commit | 73ab2ed4fd1c3cd974851be4f13e7a276ab16acf (patch) | |
tree | 3ad2775595b995f94c19ac54b3ab70cbf86e8cfe /src/nix-env/main.cc | |
parent | 7c0fa4474f0010f8266b85e891ca6049595ecb32 (diff) |
* A command `--list-generations' to show all generations for a
profile.
Diffstat (limited to 'src/nix-env/main.cc')
-rw-r--r-- | src/nix-env/main.cc | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/src/nix-env/main.cc b/src/nix-env/main.cc index 87190b620990..6aa342c1daff 100644 --- a/src/nix-env/main.cc +++ b/src/nix-env/main.cc @@ -1,5 +1,3 @@ -#include <cerrno> - #include "profiles.hh" #include "names.hh" #include "globals.hh" @@ -9,6 +7,9 @@ #include "eval.hh" #include "help.txt.hh" +#include <cerrno> +#include <ctime> + struct Globals { @@ -460,9 +461,9 @@ static void opSwitchProfile(Globals & globals, Strings opFlags, Strings opArgs) { if (opFlags.size() > 0) - throw UsageError(format("unknown flags `%1%'") % opFlags.front()); + throw UsageError(format("unknown flag `%1%'") % opFlags.front()); if (opArgs.size() != 1) - throw UsageError(format("`--profile' takes exactly one argument")); + throw UsageError(format("exactly one argument expected")); Path profile = opArgs.front(); Path profileLink = getHomeDir() + "/.nix-profile"; @@ -471,13 +472,34 @@ static void opSwitchProfile(Globals & globals, } +static void opListGenerations(Globals & globals, + Strings opFlags, Strings opArgs) +{ + if (opFlags.size() > 0) + throw UsageError(format("unknown flag `%1%'") % opFlags.front()); + if (opArgs.size() != 0) + throw UsageError(format("no arguments expected")); + + Generations gens = findGenerations(globals.profile); + + for (Generations::iterator i = gens.begin(); i != gens.end(); ++i) { + tm t; + if (!localtime_r(&i->creationTime, &t)) throw Error("cannot convert time"); + cout << format("%|4| %|4|-%|02|-%|02| %|02|:%|02|:%|02|\n") + % i->number + % (t.tm_year + 1900) % (t.tm_mon + 1) % t.tm_mday + % t.tm_hour % t.tm_min % t.tm_sec; + } +} + + static void opDefaultExpr(Globals & globals, Strings opFlags, Strings opArgs) { if (opFlags.size() > 0) throw UsageError(format("unknown flags `%1%'") % opFlags.front()); if (opArgs.size() != 1) - throw UsageError(format("`--import' takes exactly one argument")); + throw UsageError(format("exactly one argument expected")); Path defNixExpr = absPath(opArgs.front()); Path defNixExprLink = getDefNixExprPath(); @@ -526,6 +548,8 @@ void run(Strings args) } else if (arg == "--switch-profile" || arg == "-S") op = opSwitchProfile; + else if (arg == "--list-generations") + op = opListGenerations; else if (arg[0] == '-') opFlags.push_back(arg); else |