Factor out --json

This commit is contained in:
Eelco Dolstra 2017-04-24 14:21:36 +02:00
parent 9b63bb88c8
commit 66577a1c64
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
3 changed files with 14 additions and 8 deletions

View file

@ -12,7 +12,7 @@ struct MixCommonArgs : virtual Args
struct MixDryRun : virtual Args struct MixDryRun : virtual Args
{ {
bool dryRun; bool dryRun = false;
MixDryRun() MixDryRun()
{ {
@ -20,4 +20,14 @@ struct MixDryRun : virtual Args
} }
}; };
struct MixJSON : virtual Args
{
bool json = false;
MixJSON()
{
mkFlag(0, "json", "produce JSON output", &json);
}
};
} }

View file

@ -2,25 +2,24 @@
#include "shared.hh" #include "shared.hh"
#include "store-api.hh" #include "store-api.hh"
#include "json.hh" #include "json.hh"
#include "common-args.hh"
#include <iomanip> #include <iomanip>
#include <algorithm> #include <algorithm>
using namespace nix; using namespace nix;
struct CmdPathInfo : StorePathsCommand struct CmdPathInfo : StorePathsCommand, MixJSON
{ {
bool showSize = false; bool showSize = false;
bool showClosureSize = false; bool showClosureSize = false;
bool showSigs = false; bool showSigs = false;
bool json = false;
CmdPathInfo() CmdPathInfo()
{ {
mkFlag('s', "size", "print size of the NAR dump of each path", &showSize); mkFlag('s', "size", "print size of the NAR dump of each path", &showSize);
mkFlag('S', "closure-size", "print sum size of the NAR dumps of the closure of each path", &showClosureSize); mkFlag('S', "closure-size", "print sum size of the NAR dumps of the closure of each path", &showClosureSize);
mkFlag(0, "sigs", "show signatures", &showSigs); mkFlag(0, "sigs", "show signatures", &showSigs);
mkFlag(0, "json", "produce JSON output", &json);
} }
std::string name() override std::string name() override

View file

@ -7,13 +7,10 @@
using namespace nix; using namespace nix;
struct CmdShowConfig : Command struct CmdShowConfig : Command, MixJSON
{ {
bool json = false;
CmdShowConfig() CmdShowConfig()
{ {
mkFlag(0, "json", "produce JSON output", &json);
} }
std::string name() override std::string name() override