Skip to content

feat: improve dde-dconfig CLI with empty appid support and enhanced shell completions - #155

Merged
18202781743 merged 1 commit into
linuxdeepin:masterfrom
18202781743:master
Jul 15, 2026
Merged

feat: improve dde-dconfig CLI with empty appid support and enhanced shell completions#155
18202781743 merged 1 commit into
linuxdeepin:masterfrom
18202781743:master

Conversation

@18202781743

Copy link
Copy Markdown
Contributor

Overhaul the dde-dconfig command-line tool and its shell completions to
properly support application-independent configurations (empty appid)
and provide context-sensitive, multi-level tab completions for Bash
and Zsh.

Key changes:

  1. Add availableResourcesForApp() helper to return both app-specific
    and generic resources, enabling proper enumeration when appid is empty
  2. Rewrite Bash completion script: track command, positionals, and
    options independently; offer appid/resource/key suggestions based on
    current context; support -s subpath with leading-slash completion
    only; handle empty appid ('') correctly; suppress duplicate options
    already on the command line
  3. Rewrite Zsh completion script: same context-aware logic as Bash; use
    _arguments with ->state for comprehensive option descriptions; add
    dynamic resource/key lookups; handle empty appid; support -s subpath
    completion; expose all CLI options per subcommand
  4. Fix CLI key and appid parsing: use relative position index based on
    whether -a is set, so positional keys work correctly regardless of how
    appid is supplied
  5. Strip quotes from empty appid arguments passed by completions (""
    and '')
  6. Add isDefaultValue to list of get methods
  7. Update documentation with examples for empty appid usage and subpath
    behavior; fix command name typo in docs
  8. Update example script to use correct empty appid command syntax

Log: Improved dde-dconfig CLI with full empty appid support and context-
aware tab completions for both Bash and Zsh shells.

Influence:

  1. Test dde-dconfig list without arguments - should list all appids
  2. Test dde-dconfig list -a "" - should list generic resources only
  3. Test tab completion after dde-dconfig list - should suggest appids
  4. Test tab completion after dde-dconfig list -a dconfig-example -
    should suggest -r
  5. Test tab completion after dde-dconfig get -a "" -r example -
    should suggest keys
  6. Test dde-dconfig get '' -r example key1 - should work like -a "" -r example -k key1
  7. Test dde-dconfig get -a dconfig-example -r example -s /runtime/path -k key1 - subpath passed through without validation
  8. Test dde-dconfig get with -m option - should list methods
    including isDefaultValue
  9. Verify Bash and Zsh completions produce same suggestions in all
    scenarios
  10. Test with explicitly empty quoted arguments ("" or '') passed
    by completions
  11. Regression: all existing functional tests for list, get, set,
    reset, watch, gui commands should pass

feat: 改进 dde-dconfig CLI 支持空 appid 并增强 shell 补全

对 dde-dconfig 命令行工具及其 shell 补全进行全面重构,以正确支持应用无关
配置(空 appid),并为 Bash 和 Zsh 提供上下文感知的多级 Tab 补全。

主要变更:

  1. 添加 availableResourcesForApp() 辅助函数,返回应用特定资源和通用资
    源的并集,使 appid 为空时也能正确枚举
  2. 重写 Bash 补全脚本:独立跟踪命令、位置参数和选项;根据当前上下文提
    供 appid/resource/key 建议;支持 -s 子路径仅补全起始斜杠;正确处理空
    appid('');抑制已在命令行中的重复选项
  3. 重写 Zsh 补全脚本:逻辑同 Bash;使用带有 ->state_arguments
    供全面的选项描述;支持动态 resource/key 查找;处理空 appid;支持 -s
    路径补全;按子命令暴露所有 CLI 选项
  4. 修复 CLI key 和 appid 解析:根据是否设置 -a 使用相对位置索引,使位
    置参数形式的 key 无论 appid 如何提供都能正确工作
  5. 去除补全传递的空 appid 参数(""'')的引号
  6. isDefaultValue 添加到 get 的方法列表中
  7. 更新文档,包含空 appid 使用和子路径行为的示例;修复文档中的命令名称拼
    写错误
  8. 更新示例脚本,使用正确的空 appid 命令语法

Log: 改进 dde-dconfig CLI,支持完整的空 appid 功能和 Bash/Zsh 上下文感知
的 Tab 补全。

Influence:

  1. 测试 dde-dconfig list 无参数 - 应列出所有 appid
  2. 测试 dde-dconfig list -a "" - 应仅列出通用资源
  3. 测试 dde-dconfig list 后按 Tab 补全 - 应建议 appid
  4. 测试 dde-dconfig list -a dconfig-example 后按 Tab 补全 - 应建
    -r
  5. 测试 dde-dconfig get -a "" -r example 后按 Tab 补全 - 应建议 key
  6. 测试 dde-dconfig get '' -r example key1 - 应与 -a "" -r example -k key1 等效
  7. 测试 dde-dconfig get -a dconfig-example -r example -s /runtime/path -k key1 - 子路径直接传递,不验证
  8. 测试 dde-dconfig get-m 选项 - 应列出方法,包括
    isDefaultValue
  9. 验证 Bash 和 Zsh 补全在所有场景下给出相同建议
  10. 测试补全传递的显式空引用参数(""''
  11. 回归测试:所有现有的 list、get、set、reset、watch、gui 功能测试应
    通过

shell completions

Overhaul the dde-dconfig command-line tool and its shell completions to
properly support application-independent configurations (empty appid)
and provide context-sensitive, multi-level tab completions for Bash
and Zsh.

Key changes:
1. Add `availableResourcesForApp()` helper to return both app-specific
and generic resources, enabling proper enumeration when appid is empty
2. Rewrite Bash completion script: track command, positionals, and
options independently; offer appid/resource/key suggestions based on
current context; support `-s` subpath with leading-slash completion
only; handle empty appid (`''`) correctly; suppress duplicate options
already on the command line
3. Rewrite Zsh completion script: same context-aware logic as Bash; use
`_arguments` with `->state` for comprehensive option descriptions; add
dynamic resource/key lookups; handle empty appid; support `-s` subpath
completion; expose all CLI options per subcommand
4. Fix CLI key and appid parsing: use relative position index based on
whether `-a` is set, so positional keys work correctly regardless of how
appid is supplied
5. Strip quotes from empty appid arguments passed by completions (`""`
and `''`)
6. Add `isDefaultValue` to list of get methods
7. Update documentation with examples for empty appid usage and subpath
behavior; fix command name typo in docs
8. Update example script to use correct empty appid command syntax

Log: Improved dde-dconfig CLI with full empty appid support and context-
aware tab completions for both Bash and Zsh shells.

Influence:
1. Test `dde-dconfig list` without arguments - should list all appids
2. Test `dde-dconfig list -a ""` - should list generic resources only
3. Test tab completion after `dde-dconfig list ` - should suggest appids
4. Test tab completion after `dde-dconfig list -a dconfig-example ` -
should suggest `-r`
5. Test tab completion after `dde-dconfig get -a "" -r example ` -
should suggest keys
6. Test `dde-dconfig get '' -r example key1` - should work like `-a ""
-r example -k key1`
7. Test `dde-dconfig get -a dconfig-example -r example -s /runtime/path
-k key1` - subpath passed through without validation
8. Test `dde-dconfig get` with `-m` option - should list methods
including `isDefaultValue`
9. Verify Bash and Zsh completions produce same suggestions in all
scenarios
10. Test with explicitly empty quoted arguments (`""` or `''`) passed
by completions
11. Regression: all existing functional tests for `list`, `get`, `set`,
`reset`, `watch`, `gui` commands should pass

feat: 改进 dde-dconfig CLI 支持空 appid 并增强 shell 补全

对 dde-dconfig 命令行工具及其 shell 补全进行全面重构,以正确支持应用无关
配置(空 appid),并为 Bash 和 Zsh 提供上下文感知的多级 Tab 补全。

主要变更:
1. 添加 `availableResourcesForApp()` 辅助函数,返回应用特定资源和通用资
源的并集,使 appid 为空时也能正确枚举
2. 重写 Bash 补全脚本:独立跟踪命令、位置参数和选项;根据当前上下文提
供 appid/resource/key 建议;支持 `-s` 子路径仅补全起始斜杠;正确处理空
appid(`''`);抑制已在命令行中的重复选项
3. 重写 Zsh 补全脚本:逻辑同 Bash;使用带有 `->state` 的 `_arguments` 提
供全面的选项描述;支持动态 resource/key 查找;处理空 appid;支持 `-s` 子
路径补全;按子命令暴露所有 CLI 选项
4. 修复 CLI key 和 appid 解析:根据是否设置 `-a` 使用相对位置索引,使位
置参数形式的 key 无论 appid 如何提供都能正确工作
5. 去除补全传递的空 appid 参数(`""` 和 `''`)的引号
6. 将 `isDefaultValue` 添加到 get 的方法列表中
7. 更新文档,包含空 appid 使用和子路径行为的示例;修复文档中的命令名称拼
写错误
8. 更新示例脚本,使用正确的空 appid 命令语法

Log: 改进 dde-dconfig CLI,支持完整的空 appid 功能和 Bash/Zsh 上下文感知
的 Tab 补全。

Influence:
1. 测试 `dde-dconfig list` 无参数 - 应列出所有 appid
2. 测试 `dde-dconfig list -a ""` - 应仅列出通用资源
3. 测试 `dde-dconfig list ` 后按 Tab 补全 - 应建议 appid
4. 测试 `dde-dconfig list -a dconfig-example ` 后按 Tab 补全 - 应建
议 `-r`
5. 测试 `dde-dconfig get -a "" -r example ` 后按 Tab 补全 - 应建议 key
6. 测试 `dde-dconfig get '' -r example key1` - 应与 `-a "" -r example -k
key1` 等效
7. 测试 `dde-dconfig get -a dconfig-example -r example -s /runtime/path
-k key1` - 子路径直接传递,不验证
8. 测试 `dde-dconfig get` 带 `-m` 选项 - 应列出方法,包括
`isDefaultValue`
9. 验证 Bash 和 Zsh 补全在所有场景下给出相同建议
10. 测试补全传递的显式空引用参数(`""` 或 `''`)
11. 回归测试:所有现有的 list、get、set、reset、watch、gui 功能测试应
通过
@18202781743
18202781743 requested review from BLumia and mhduiy July 14, 2026 09:55

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @18202781743, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@github-actions

Copy link
Copy Markdown
  • 检测到敏感词unset变动
详情
    {
    "unset": {
        "dconfig-center/dde-dconfig/completion/dde-dconfig.bash": {
            "a": [
                "\t\t\t\t[[ ${COMPREPLY[j]} == \"$i\" ]] && unset 'COMPREPLY[j]'"
            ]
        }
    }
}

@github-actions

Copy link
Copy Markdown

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码实现了对dde-dconfig命令行工具的补全逻辑重构及空appid支持,逻辑严谨且注释清晰
代码质量良好,无安全漏洞,仅在兼容性处理上存在轻微逻辑妥协,扣5分

■ 【详细分析】

  • 1.语法逻辑(基本正确)✓

helper.hpp中新增的availableResourcesForApp函数正确使用QSet进行资源去重,逻辑清晰。main.cppfetchKeyisSetKey根据appidOption是否设置动态调整位置参数索引,逻辑正确。fetchAppid中对引号字符串的兼容处理合理。listCommand中允许空appid查询通用资源的逻辑正确。
潜在问题:fetchAppid中将""''字符串直接转换为空字符串,若用户真实appid为这两个字面量字符串则会被误判,但实际场景概率极低。
建议:无需特别修改,当前处理方式在兼容性和准确性之间取得了合理平衡。

  • 2.代码质量(良好)✓

代码结构清晰,函数职责单一。bash和zsh补全脚本中添加了详细的注释说明设计意图,如空appid的处理、位置参数的推断等。文档和示例脚本同步更新,保持了良好的一致性。
潜在问题:bash和zsh补全脚本中存在大量逻辑相似的代码,但由于shell语法差异难以直接复用。
建议:保持现状,这是shell补全脚本的常见情况。

  • 3.代码性能(无性能问题)✓

availableResourcesForApp使用QSet去重效率较高。补全脚本中调用外部命令获取候选列表时使用了command关键字避免函数递归,并通过数组批量处理结果,避免了不必要的性能损耗。
建议:无需优化。

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码在处理外部输入和调用子进程时均采取了安全措施,如使用双引号包裹变量防止参数分裂,未发现注入风险。
建议:保持当前安全编码实践。

■ 【改进建议代码示例】

// main.cpp 中 fetchAppid 的逻辑已较为完善,若需进一步明确字面量处理,可增加注释
inline QString fetchAppid() const
{
    QString value;
    if (parser.isSet(appidOption)) {
        value = parser.value(appidOption);
    } else if (parser.positionalArguments().size() > 1) {
        value = parser.positionalArguments().at(1);
    }

    // 兼容部分补全引擎保留引号的行为,将显式空引号视为空appid
    if (value == QStringLiteral("\"\"") || value == QStringLiteral("''"))
        return QString();
    return value;
}

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, BLumia

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@18202781743
18202781743 merged commit e15724a into linuxdeepin:master Jul 15, 2026
22 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants