Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Helpdoc): 使用帮助文档分组的别名时标题搜索失效 (Cherrypick #1120) #1121

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions dice/builtin_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,12 @@ func (d *Dice) registerCoreCommands() {
var (
useGroupSearch bool
group string
text string = cmdArgs.CleanArgs
)
if _group := cmdArgs.GetArgN(1); strings.HasPrefix(_group, "#") {
if rawGroup := cmdArgs.GetArgN(1); strings.HasPrefix(rawGroup, "#") {
useGroupSearch = true
fakeGroup := strings.TrimPrefix(_group, "#")
fakeGroup := strings.TrimPrefix(rawGroup, "#")
text = strings.TrimPrefix(text, rawGroup+" ")

// 转换 group 别名
if _g, ok := d.Parent.Help.GroupAliases[fakeGroup]; ok {
Expand Down Expand Up @@ -279,14 +281,16 @@ func (d *Dice) registerCoreCommands() {
return CmdExecuteResult{Matched: true, Solved: true}
}

var val string
if useGroupSearch {
val = cmdArgs.GetArgN(2)
} else {
val = cmdArgs.GetArgN(1)
}
if val == "" {
return CmdExecuteResult{Matched: true, Solved: true, ShowHelp: true}
{ // 判断是否关键字缺失
var val string
if useGroupSearch {
val = cmdArgs.GetArgN(2)
} else {
val = cmdArgs.GetArgN(1)
}
if val == "" {
return CmdExecuteResult{Matched: true, Solved: true, ShowHelp: true}
}
}

numLimit := 4
Expand All @@ -306,8 +310,6 @@ func (d *Dice) registerCoreCommands() {
}
}

text := strings.TrimPrefix(cmdArgs.CleanArgs, "#"+group+" ")

if numLimit <= 0 {
numLimit = 1
} else if numLimit > 10 {
Expand Down