fix(cli): 按模式展示查询默认值并保留传统采样次数

This commit is contained in:
tsosunchia committed 2026-09-06 11:24:11 +08:00
1 parent abe3ef387f
commit 5207c32a01
5 files changed
+41 -7

No files matched your search

+1 -2
View File
@@ -894,8 +894,7 @@ Arguments:
-q --queries Traceroute: latency samples per hop
(default 3). MTR: max probes per hop;
TUI/raw defaults to 0 (unlimited),
--report defaults to 10 when omitted.
Default: 3
--report defaults to 10 when omitted
--max-attempts Advanced: hard cap on probe packets per
hop. Leave unset for auto sizing; raise on
lossy links if --queries is not enough
+1 -2
View File
@@ -869,8 +869,7 @@ Arguments:
-q --queries Traceroute: latency samples per hop
(default 3). MTR: max probes per hop;
TUI/raw defaults to 0 (unlimited),
--report defaults to 10 when omitted.
Default: 3
--report defaults to 10 when omitted
--max-attempts Advanced: hard cap on probe packets per
hop. Leave unset for auto sizing; raise on
lossy links if --queries is not enough
+9 -1
View File
@@ -395,6 +395,14 @@ func registerDataProviderFlag(parser *argparse.Parser) *string {
})
}
func registerQueriesFlag(parser *argparse.Parser) *int {
queries := parser.Int("q", "queries", &argparse.Options{Help: buildQueriesHelp()})
// Keep the traditional fallback without argparse advertising it for every mode.
// MTR applies its own defaults when this flag was not explicitly parsed.
*queries = 3
return queries
}
func buildQueriesHelp() string {
if !enableTraceroute {
return "MTR only: max probes per hop. 0 = unlimited in TUI/raw; --report defaults to 10 when omitted. Start with 10-20 on unstable paths"
@@ -1373,7 +1381,7 @@ func Execute() {
fastTraceFlag := registerFastTraceFlag(parser)
port := parser.Int("p", "port", &argparse.Options{Help: "Set the destination port to use. With default of 80 for \"tcp\", 33494 for \"udp\""})
icmpMode := registerICMPModeFlag(parser)
numMeasurements := parser.Int("q", "queries", &argparse.Options{Default: 3, Help: buildQueriesHelp()})
numMeasurements := registerQueriesFlag(parser)
maxAttempts := parser.Int("", "max-attempts", &argparse.Options{Help: buildMaxAttemptsHelp()})
parallelRequests := parser.Int("", "parallel-requests", &argparse.Options{Default: 18, Help: buildParallelRequestsHelp()})
maxHops := parser.Int("m", "max-hops", &argparse.Options{Default: 30, Help: "Set the max number of hops (max TTL to be reached)"})
+28
View File
@@ -1074,6 +1074,34 @@ func TestQueriesHelpDescribesModeSemantics(t *testing.T) {
if enableTraceroute && !strings.Contains(help, "Traceroute: latency samples per hop (default 3)") {
t.Fatalf("queries help missing traditional semantics: %s", help)
}
if !enableTraceroute && !strings.HasPrefix(help, "MTR only: max probes per hop.") {
t.Fatalf("queries help missing MTR-only semantics: %s", help)
}
}
func TestQueriesFlagDefaultsAndHelp(t *testing.T) {
for _, tc := range []struct {
args []string
want int
explicit bool
}{
{nil, 3, false},
{[]string{"-q", "0"}, 0, true},
{[]string{"--queries", "10"}, 10, true},
} {
parser := argparse.NewParser(appBinName, "")
queries := registerQueriesFlag(parser)
if err := parser.Parse(append([]string{appBinName}, tc.args...)); err != nil {
t.Fatal(err)
}
explicit, _, _, _ := detectExplicitProbeFlags(parser)
if *queries != tc.want || explicit != tc.explicit {
t.Fatalf("%v: queries=%d explicit=%v", tc.args, *queries, explicit)
}
if strings.Contains(parser.Usage(nil), "Default: 3") {
t.Fatal("queries help advertises an unconditional default")
}
}
}
func TestAdvancedHelpTextMentionsTuningGuidance(t *testing.T) {
+2 -2
View File
@@ -16,8 +16,8 @@
| UPX 产物 | 基线字节 | 本次实现字节 | 差值 |
|---|---:|---:|---:|
| Linux amd64 | 4,733,908 | 4,553,524 | -180,384 |
| Linux arm64 | 4,129,916 | 4,132,428 | +2,512 |
| Linux amd64 | 4,733,908 | 4,553,388 | -180,520 |
| Linux arm64 | 4,129,916 | 4,132,492 | +2,576 |
规划阶段仅将基线 tiny 的 `enableMTR` 改为 `true`,未压缩体积也均未变化,UPX amd64/arm64 分别增加 624/1,012 字节。本次实现还包含显式传统模式和模式解析准备,因此应使用上表作为本次整体变更的比较。