Merge bitcoin/bitcoin#24306: util: Make ArgsManager::GetPathArg more widely usable

60aa179d8f Use GetPathArg where possible (Pavol Rusnak)
5b946edd73 util, refactor: Use GetPathArg to read "-settings" value (Ryan Ofsky)
687e655ae2 util: Add GetPathArg default path argument (Ryan Ofsky)

Pull request description:

  Improve `ArgsManager::GetPathArg` method added in recent PR #24265, so it is usable more places. This PR starts to use it for the `-settings` option. This can also be helpful for #24274 which is parsing more path options.

  - Add `GetPathArg` default argument so it is less awkward to use to parse options that have default values.
  - Fix `GetPathArg` negated argument handling. Return path{} not path{"0"} when path argument is negated.
  - Add unit tests for default and negated cases
  - Move `GetPathArg` method declaration next to `GetArg` declaration. The two methods are close substitutes for each, so this should help keep them consistent and make them more discoverable.

ACKs for top commit:
  w0xlt:
    Tested ACK 60aa179 on Ubuntu 21.10
  hebasto:
    re-ACK 60aa179d8f

Tree-SHA512: 3d24b885d8bbeef39ea5d0556e2f09b9e5f4a21179cef11cbbbc1b84da29c8fb66ba698889054ce28d80bc25926687654c8532ed46054bf5b2dd1837866bd1cd
This commit is contained in:
MarcoFalke
2022-03-07 10:00:38 +01:00
6 changed files with 43 additions and 23 deletions

View File

@@ -245,6 +245,24 @@ BOOST_AUTO_TEST_CASE(patharg)
ResetArgs(local_args, "-dir=user/.bitcoin/.//");
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir"), relative_path);
// Check negated and default argument handling. Specifying an empty argument
// is the same as not specifying the argument. This is convenient for
// scripting so later command line arguments can override earlier command
// line arguments or bitcoin.conf values. Currently the -dir= case cannot be
// distinguished from -dir case with no assignment, but #16545 would add the
// ability to distinguish these in the future (and treat the no-assign case
// like an imperative command or an error).
ResetArgs(local_args, "");
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir", "default"), fs::path{"default"});
ResetArgs(local_args, "-dir=override");
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir", "default"), fs::path{"override"});
ResetArgs(local_args, "-dir=");
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir", "default"), fs::path{"default"});
ResetArgs(local_args, "-dir");
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir", "default"), fs::path{"default"});
ResetArgs(local_args, "-nodir");
BOOST_CHECK_EQUAL(local_args.GetPathArg("-dir", "default"), fs::path{""});
}
BOOST_AUTO_TEST_CASE(doubledash)