From 450dcf2c1b60a36f5ffeab2411805287d122bcdd Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 2 Jun 2020 15:52:13 +0000 Subject: Remove `HashType::Unknown` Instead, `Hash` uses `std::optional`. In the future, we may also make `Hash` itself require a known hash type, encoraging people to use `std::optional` instead. --- src/nix/hash.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/nix/hash.cc') diff --git a/src/nix/hash.cc b/src/nix/hash.cc index 3362ffd0d..4980cd198 100644 --- a/src/nix/hash.cc +++ b/src/nix/hash.cc @@ -79,7 +79,7 @@ static RegisterCommand r2("hash-path", [](){ return make_ref(FileIngest struct CmdToBase : Command { Base base; - HashType ht = HashType::Unknown; + HashType ht; std::vector args; CmdToBase(Base base) : base(base) @@ -132,8 +132,6 @@ static int compatNixHash(int argc, char * * argv) else if (*arg == "--type") { string s = getArg(*arg, arg, end); ht = parseHashType(s); - if (ht == HashType::Unknown) - throw UsageError(format("unknown hash type '%1%'") % s); } else if (*arg == "--to-base16") op = opTo16; else if (*arg == "--to-base32") op = opTo32; -- cgit v1.2.3 From c502119fd3b9673e966d5c34ec42cbe18baa17b9 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 2 Jun 2020 18:05:26 +0000 Subject: to-base supports parsing SRI hashes, so make type flag optional --- src/nix/hash.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nix/hash.cc') diff --git a/src/nix/hash.cc b/src/nix/hash.cc index 4980cd198..0e24bbaed 100644 --- a/src/nix/hash.cc +++ b/src/nix/hash.cc @@ -79,12 +79,12 @@ static RegisterCommand r2("hash-path", [](){ return make_ref(FileIngest struct CmdToBase : Command { Base base; - HashType ht; + std::optional ht; std::vector args; CmdToBase(Base base) : base(base) { - addFlag(Flag::mkHashTypeFlag("type", &ht)); + addFlag(Flag::mkHashTypeFlag("type", &*ht)); expectArgs("strings", &args); } -- cgit v1.2.3 From c664e68b87a3e9e41c4471276886da71793b2d85 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 2 Jun 2020 18:25:32 +0000 Subject: Fix to-base --type handler to correctly set std::optional flag Now that we have a separate flag function, also describe why it is optional. --- src/nix/hash.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nix/hash.cc') diff --git a/src/nix/hash.cc b/src/nix/hash.cc index 0e24bbaed..d1b5cca72 100644 --- a/src/nix/hash.cc +++ b/src/nix/hash.cc @@ -84,7 +84,7 @@ struct CmdToBase : Command CmdToBase(Base base) : base(base) { - addFlag(Flag::mkHashTypeFlag("type", &*ht)); + addFlag(Flag::mkHashTypeOptFlag("type", &ht)); expectArgs("strings", &args); } -- cgit v1.2.3