From 9c14fa58d8ca1d9ef8468001a2b7864ced468f9d Mon Sep 17 00:00:00 2001 From: Yat Ho Date: Thu, 16 Oct 2025 01:08:11 +0800 Subject: [PATCH] feat: allow optional arguments in `tr_getopt()` (#7510) * feat: allow optional arguments in `tr_getopt()` * test: new tests for optional arg * code review: `using Arg = tr_option::Arg` * refactor: static assert option array size * test: add new tests for missing arguments in the middle * test: static auto constexpr --- cli/cli.cc | 61 ++--- daemon/daemon.cc | 149 +++++++------ libtransmission/tr-getopt.cc | 48 ++-- libtransmission/tr-getopt.h | 14 +- qt/main.cc | 25 ++- tests/libtransmission/getopt-test.cc | 229 +++++++++++++------ utils/create.cc | 29 ++- utils/edit.cc | 21 +- utils/remote.cc | 320 ++++++++++++++------------- utils/show.cc | 42 ++-- 10 files changed, 536 insertions(+), 402 deletions(-) diff --git a/cli/cli.cc b/cli/cli.cc index 7916904d7..a4470868b 100644 --- a/cli/cli.cc +++ b/cli/cli.cc @@ -48,36 +48,41 @@ sig_atomic_t manualUpdate = false; char const* torrentPath = nullptr; -auto constexpr Options = std::array{ - { { 'b', "blocklist", "Enable peer blocklists", "b", false, nullptr }, - { 'B', "no-blocklist", "Disable peer blocklists", "B", false, nullptr }, - { 'd', "downlimit", "Set max download speed in " SPEED_K_STR, "d", true, "" }, - { 'D', "no-downlimit", "Don't limit the download speed", "D", false, nullptr }, - { 910, "encryption-required", "Encrypt all peer connections", "er", false, nullptr }, - { 911, "encryption-preferred", "Prefer encrypted peer connections", "ep", false, nullptr }, - { 912, "encryption-tolerated", "Prefer unencrypted peer connections", "et", false, nullptr }, - { 'f', "finish", "Run a script when the torrent finishes", "f", true, "