Skip to content

Commit

Permalink
fix(Helpdoc): 使用帮助文档分组的别名时标题搜索失效 (Cherrypick #1120) (#1121)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiangze-Li authored Nov 8, 2024
1 parent 9707226 commit 2a35ad1
Showing 1 changed file with 14 additions and 12 deletions.
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

0 comments on commit 2a35ad1

Please sign in to comment.