diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2019-06-18 16:01:35 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2019-12-05 20:19:26 +0100 |
commit | ac676856061677559a21670940ac2fac98add9a0 (patch) | |
tree | 0f5444034c6262f8ad92f0fd10c8dcf2b95a8e0c /src/nix/hash.cc | |
parent | f964f428fe6975e06a273e43c3266928a407454f (diff) |
Make subcommand construction in MultiCommand lazy
(cherry picked from commit a0de58f471c9087d8e6cc60a6078f9940a125b15)
Diffstat (limited to 'src/nix/hash.cc')
-rw-r--r-- | src/nix/hash.cc | 26 |
1 files changed, 6 insertions, 20 deletions
diff --git a/src/nix/hash.cc b/src/nix/hash.cc index d7451376c..0cc523f50 100644 --- a/src/nix/hash.cc +++ b/src/nix/hash.cc @@ -36,11 +36,6 @@ struct CmdHash : Command expectArgs("paths", &paths); } - std::string name() override - { - return mode == mFile ? "hash-file" : "hash-path"; - } - std::string description() override { return mode == mFile @@ -71,8 +66,8 @@ struct CmdHash : Command } }; -static RegisterCommand r1(make_ref<CmdHash>(CmdHash::mFile)); -static RegisterCommand r2(make_ref<CmdHash>(CmdHash::mPath)); +static RegisterCommand r1("hash-file", [](){ return make_ref<CmdHash>(CmdHash::mFile); }); +static RegisterCommand r2("hash-path", [](){ return make_ref<CmdHash>(CmdHash::mPath); }); struct CmdToBase : Command { @@ -88,15 +83,6 @@ struct CmdToBase : Command expectArgs("strings", &args); } - std::string name() override - { - return - base == Base16 ? "to-base16" : - base == Base32 ? "to-base32" : - base == Base64 ? "to-base64" : - "to-sri"; - } - std::string description() override { return fmt("convert a hash to %s representation", @@ -113,10 +99,10 @@ struct CmdToBase : Command } }; -static RegisterCommand r3(make_ref<CmdToBase>(Base16)); -static RegisterCommand r4(make_ref<CmdToBase>(Base32)); -static RegisterCommand r5(make_ref<CmdToBase>(Base64)); -static RegisterCommand r6(make_ref<CmdToBase>(SRI)); +static RegisterCommand r3("to-base16", [](){ return make_ref<CmdToBase>(Base16); }); +static RegisterCommand r4("to-base32", [](){ return make_ref<CmdToBase>(Base32); }); +static RegisterCommand r5("to-base64", [](){ return make_ref<CmdToBase>(Base64); }); +static RegisterCommand r6("to-sri", [](){ return make_ref<CmdToBase>(SRI); }); /* Legacy nix-hash command. */ static int compatNixHash(int argc, char * * argv) |