diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2017-04-24T12·21+0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2017-04-24T12·21+0200 |
commit | 66577a1c64ac5d9f07aa2c207c96e13077576a4e (patch) | |
tree | a4c55d9b74df73cefe28eb2f26cdb6968f250e06 | |
parent | 9b63bb88c8873d192b8b01608e5d230817dd3375 (diff) |
Factor out --json
-rw-r--r-- | src/libmain/common-args.hh | 12 | ||||
-rw-r--r-- | src/nix/path-info.cc | 5 | ||||
-rw-r--r-- | src/nix/show-config.cc | 5 |
3 files changed, 14 insertions, 8 deletions
diff --git a/src/libmain/common-args.hh b/src/libmain/common-args.hh index 2c0d71edd815..a4de3dccf0a5 100644 --- a/src/libmain/common-args.hh +++ b/src/libmain/common-args.hh @@ -12,7 +12,7 @@ struct MixCommonArgs : virtual Args struct MixDryRun : virtual Args { - bool dryRun; + bool dryRun = false; MixDryRun() { @@ -20,4 +20,14 @@ struct MixDryRun : virtual Args } }; +struct MixJSON : virtual Args +{ + bool json = false; + + MixJSON() + { + mkFlag(0, "json", "produce JSON output", &json); + } +}; + } diff --git a/src/nix/path-info.cc b/src/nix/path-info.cc index 0f9a1125f2e9..30b193798f69 100644 --- a/src/nix/path-info.cc +++ b/src/nix/path-info.cc @@ -2,25 +2,24 @@ #include "shared.hh" #include "store-api.hh" #include "json.hh" +#include "common-args.hh" #include <iomanip> #include <algorithm> using namespace nix; -struct CmdPathInfo : StorePathsCommand +struct CmdPathInfo : StorePathsCommand, MixJSON { bool showSize = false; bool showClosureSize = false; bool showSigs = false; - bool json = false; CmdPathInfo() { 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(0, "sigs", "show signatures", &showSigs); - mkFlag(0, "json", "produce JSON output", &json); } std::string name() override diff --git a/src/nix/show-config.cc b/src/nix/show-config.cc index aade2adeace4..e354891a82e4 100644 --- a/src/nix/show-config.cc +++ b/src/nix/show-config.cc @@ -7,13 +7,10 @@ using namespace nix; -struct CmdShowConfig : Command +struct CmdShowConfig : Command, MixJSON { - bool json = false; - CmdShowConfig() { - mkFlag(0, "json", "produce JSON output", &json); } std::string name() override |