mirror of
https://github.com/NixOS/nix
synced 2025-07-02 17:41:48 +02:00
remove 'format' from Error constructor calls
This commit is contained in:
parent
d3052197fe
commit
e4fb9a3849
52 changed files with 424 additions and 407 deletions
|
@ -25,7 +25,6 @@
|
|||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
using namespace nix;
|
||||
using std::cout;
|
||||
|
||||
|
@ -70,8 +69,7 @@ typedef void (* Operation) (Globals & globals,
|
|||
static string needArg(Strings::iterator & i,
|
||||
Strings & args, const string & arg)
|
||||
{
|
||||
if (i == args.end()) throw UsageError(
|
||||
format("'%1%' requires an argument") % arg);
|
||||
if (i == args.end()) throw UsageError( "'%1%' requires an argument", arg);
|
||||
return *i++;
|
||||
}
|
||||
|
||||
|
@ -133,7 +131,7 @@ static void getAllExprs(EvalState & state,
|
|||
Value & vArg(*state.allocValue());
|
||||
mkString(vArg, path2);
|
||||
if (v.attrs->size() == v.attrs->capacity())
|
||||
throw Error(format("too many Nix expressions in directory '%1%'") % path);
|
||||
throw Error("too many Nix expressions in directory '%1%'", path);
|
||||
mkApp(*state.allocAttr(v, state.symbols.create(attrName)), vFun, vArg);
|
||||
}
|
||||
else if (S_ISDIR(st.st_mode))
|
||||
|
@ -144,11 +142,12 @@ static void getAllExprs(EvalState & state,
|
|||
}
|
||||
|
||||
|
||||
|
||||
static void loadSourceExpr(EvalState & state, const Path & path, Value & v)
|
||||
{
|
||||
struct stat st;
|
||||
if (stat(path.c_str(), &st) == -1)
|
||||
throw SysError(format("getting information about '%1%'") % path);
|
||||
throw SysError("getting inon about '%1%'", path);
|
||||
|
||||
if (isNixExpr(path, st))
|
||||
state.evalFile(path, v);
|
||||
|
@ -221,7 +220,7 @@ static void checkSelectorUse(DrvNames & selectors)
|
|||
/* Check that all selectors have been used. */
|
||||
for (auto & i : selectors)
|
||||
if (i.hits == 0 && i.fullName != "*")
|
||||
throw Error(format("selector '%1%' matches no derivations") % i.fullName);
|
||||
throw Error("selector '%1%' matches no derivations", i.fullName);
|
||||
}
|
||||
|
||||
|
||||
|
@ -507,7 +506,7 @@ static void opInstall(Globals & globals, Strings opFlags, Strings opArgs)
|
|||
globals.preserveInstalled = true;
|
||||
else if (arg == "--remove-all" || arg == "-r")
|
||||
globals.removeAll = true;
|
||||
else throw UsageError(format("unknown flag '%1%'") % arg);
|
||||
else throw UsageError("unknown flag '%1%'", arg);
|
||||
}
|
||||
|
||||
installDerivations(globals, opArgs, globals.profile);
|
||||
|
@ -618,7 +617,7 @@ static void opUpgrade(Globals & globals, Strings opFlags, Strings opArgs)
|
|||
else if (arg == "--leq") upgradeType = utLeq;
|
||||
else if (arg == "--eq") upgradeType = utEq;
|
||||
else if (arg == "--always") upgradeType = utAlways;
|
||||
else throw UsageError(format("unknown flag '%1%'") % arg);
|
||||
else throw UsageError("unknown flag '%1%'", arg);
|
||||
}
|
||||
|
||||
upgradeDerivations(globals, opArgs, upgradeType);
|
||||
|
@ -637,7 +636,7 @@ static void setMetaFlag(EvalState & state, DrvInfo & drv,
|
|||
static void opSetFlag(Globals & globals, Strings opFlags, Strings opArgs)
|
||||
{
|
||||
if (opFlags.size() > 0)
|
||||
throw UsageError(format("unknown flag '%1%'") % opFlags.front());
|
||||
throw UsageError("unknown flag '%1%'", opFlags.front());
|
||||
if (opArgs.size() < 2)
|
||||
throw UsageError("not enough arguments to '--set-flag'");
|
||||
|
||||
|
@ -680,7 +679,7 @@ static void opSet(Globals & globals, Strings opFlags, Strings opArgs)
|
|||
for (Strings::iterator i = opFlags.begin(); i != opFlags.end(); ) {
|
||||
string arg = *i++;
|
||||
if (parseInstallSourceOptions(globals, i, opFlags, arg)) ;
|
||||
else throw UsageError(format("unknown flag '%1%'") % arg);
|
||||
else throw UsageError("unknown flag '%1%'", arg);
|
||||
}
|
||||
|
||||
DrvInfos elems;
|
||||
|
@ -748,7 +747,7 @@ static void uninstallDerivations(Globals & globals, Strings & selectors,
|
|||
static void opUninstall(Globals & globals, Strings opFlags, Strings opArgs)
|
||||
{
|
||||
if (opFlags.size() > 0)
|
||||
throw UsageError(format("unknown flag '%1%'") % opFlags.front());
|
||||
throw UsageError("unknown flag '%1%'", opFlags.front());
|
||||
uninstallDerivations(globals, opArgs, globals.profile);
|
||||
}
|
||||
|
||||
|
@ -911,7 +910,7 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
|
|||
else if (arg == "--attr" || arg == "-A")
|
||||
attrPath = needArg(i, opFlags, arg);
|
||||
else
|
||||
throw UsageError(format("unknown flag '%1%'") % arg);
|
||||
throw UsageError("unknown flag '%1%'", arg);
|
||||
}
|
||||
|
||||
if (printAttrPath && source != sAvailable)
|
||||
|
@ -1177,9 +1176,9 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
|
|||
static void opSwitchProfile(Globals & globals, Strings opFlags, Strings opArgs)
|
||||
{
|
||||
if (opFlags.size() > 0)
|
||||
throw UsageError(format("unknown flag '%1%'") % opFlags.front());
|
||||
throw UsageError("unknown flag '%1%'", opFlags.front());
|
||||
if (opArgs.size() != 1)
|
||||
throw UsageError(format("exactly one argument expected"));
|
||||
throw UsageError("exactly one argument expected");
|
||||
|
||||
Path profile = absPath(opArgs.front());
|
||||
Path profileLink = getHome() + "/.nix-profile";
|
||||
|
@ -1207,10 +1206,10 @@ static void switchGeneration(Globals & globals, int dstGen)
|
|||
|
||||
if (!dst) {
|
||||
if (dstGen == prevGen)
|
||||
throw Error(format("no generation older than the current (%1%) exists")
|
||||
% curGen);
|
||||
throw Error("no generation older than the current (%1%) exists",
|
||||
curGen);
|
||||
else
|
||||
throw Error(format("generation %1% does not exist") % dstGen);
|
||||
throw Error("generation %1% does not exist", dstGen);
|
||||
}
|
||||
|
||||
printInfo(format("switching from generation %1% to %2%")
|
||||
|
@ -1225,13 +1224,13 @@ static void switchGeneration(Globals & globals, int dstGen)
|
|||
static void opSwitchGeneration(Globals & globals, Strings opFlags, Strings opArgs)
|
||||
{
|
||||
if (opFlags.size() > 0)
|
||||
throw UsageError(format("unknown flag '%1%'") % opFlags.front());
|
||||
throw UsageError("unknown flag '%1%'", opFlags.front());
|
||||
if (opArgs.size() != 1)
|
||||
throw UsageError(format("exactly one argument expected"));
|
||||
throw UsageError("exactly one argument expected");
|
||||
|
||||
int dstGen;
|
||||
if (!string2Int(opArgs.front(), dstGen))
|
||||
throw UsageError(format("expected a generation number"));
|
||||
throw UsageError("expected a generation number");
|
||||
|
||||
switchGeneration(globals, dstGen);
|
||||
}
|
||||
|
@ -1240,9 +1239,9 @@ static void opSwitchGeneration(Globals & globals, Strings opFlags, Strings opArg
|
|||
static void opRollback(Globals & globals, Strings opFlags, Strings opArgs)
|
||||
{
|
||||
if (opFlags.size() > 0)
|
||||
throw UsageError(format("unknown flag '%1%'") % opFlags.front());
|
||||
throw UsageError("unknown flag '%1%'", opFlags.front());
|
||||
if (opArgs.size() != 0)
|
||||
throw UsageError(format("no arguments expected"));
|
||||
throw UsageError("no arguments expected");
|
||||
|
||||
switchGeneration(globals, prevGen);
|
||||
}
|
||||
|
@ -1251,9 +1250,9 @@ static void opRollback(Globals & globals, Strings opFlags, Strings opArgs)
|
|||
static void opListGenerations(Globals & globals, Strings opFlags, Strings opArgs)
|
||||
{
|
||||
if (opFlags.size() > 0)
|
||||
throw UsageError(format("unknown flag '%1%'") % opFlags.front());
|
||||
throw UsageError("unknown flag '%1%'", opFlags.front());
|
||||
if (opArgs.size() != 0)
|
||||
throw UsageError(format("no arguments expected"));
|
||||
throw UsageError("no arguments expected");
|
||||
|
||||
PathLocks lock;
|
||||
lockProfile(lock, globals.profile);
|
||||
|
@ -1278,7 +1277,7 @@ static void opListGenerations(Globals & globals, Strings opFlags, Strings opArgs
|
|||
static void opDeleteGenerations(Globals & globals, Strings opFlags, Strings opArgs)
|
||||
{
|
||||
if (opFlags.size() > 0)
|
||||
throw UsageError(format("unknown flag '%1%'") % opFlags.front());
|
||||
throw UsageError("unknown flag '%1%'", opFlags.front());
|
||||
|
||||
if (opArgs.size() == 1 && opArgs.front() == "old") {
|
||||
deleteOldGenerations(globals.profile, globals.dryRun);
|
||||
|
@ -1286,18 +1285,18 @@ static void opDeleteGenerations(Globals & globals, Strings opFlags, Strings opAr
|
|||
deleteGenerationsOlderThan(globals.profile, opArgs.front(), globals.dryRun);
|
||||
} else if (opArgs.size() == 1 && opArgs.front().find('+') != string::npos) {
|
||||
if(opArgs.front().size() < 2)
|
||||
throw Error(format("invalid number of generations ‘%1%’") % opArgs.front());
|
||||
throw Error("invalid number of generations ‘%1%’", opArgs.front());
|
||||
string str_max = string(opArgs.front(), 1, opArgs.front().size());
|
||||
int max;
|
||||
if (!string2Int(str_max, max) || max == 0)
|
||||
throw Error(format("invalid number of generations to keep ‘%1%’") % opArgs.front());
|
||||
throw Error("invalid number of generations to keep ‘%1%’", opArgs.front());
|
||||
deleteGenerationsGreaterThan(globals.profile, max, globals.dryRun);
|
||||
} else {
|
||||
std::set<unsigned int> gens;
|
||||
for (auto & i : opArgs) {
|
||||
unsigned int n;
|
||||
if (!string2Int(i, n))
|
||||
throw UsageError(format("invalid generation number '%1%'") % i);
|
||||
throw UsageError("invalid generation number '%1%'", i);
|
||||
gens.insert(n);
|
||||
}
|
||||
deleteGenerations(globals.profile, gens, globals.dryRun);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue