add-command
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAdd support for in Dippy.
$ARGUMENTS为Dippy中的添加支持。
$ARGUMENTS1. Research
1. 调研
tldr pages:
ls ~/source/tldr/pages/*/$ARGUMENTS*.md
cat ~/source/tldr/pages/*/$ARGUMENTS.mdCLI docs:
$ARGUMENTS --help
man $ARGUMENTSNote which operations are read-only vs mutations.
tldr页面:
ls ~/source/tldr/pages/*/$ARGUMENTS*.md
cat ~/source/tldr/pages/*/$ARGUMENTS.mdCLI文档:
$ARGUMENTS --help
man $ARGUMENTS记录哪些操作是只读的,哪些是变更操作。
2. Decide: Handler or SIMPLE_SAFE?
2. 决策:使用Handler还是SIMPLE_SAFE?
- SIMPLE_SAFE: Always safe regardless of arguments (read-only, no destructive flags). Go to step 3A.
- Handler: Needs subcommand/flag analysis. Go to step 3B.
- SIMPLE_SAFE:无论传入什么参数都始终安全(只读,无破坏性标识)。跳转至步骤3A。
- Handler:需要进行子命令/标识分析。跳转至步骤3B。
3A. SIMPLE_SAFE Path
3A. SIMPLE_SAFE路径
Add to in and add tests to in the appropriate category. Skip to step 5.
SIMPLE_SAFEsrc/dippy/core/allowlists.pytests/test_simple.py添加到的列表中,并在的对应分类下添加测试用例。跳转至步骤5。
src/dippy/core/allowlists.pySIMPLE_SAFEtests/test_simple.py3B. Handler Path
3B. Handler路径
Create :
tests/cli/test_$ARGUMENTS.pypython
"""Test cases for $ARGUMENTS."""
import pytest
from conftest import is_approved, needs_confirmation
TESTS = [
# Safe operations
("$ARGUMENTS <safe-subcommand>", True),
("$ARGUMENTS --help", True),
# Unsafe operations
("$ARGUMENTS <unsafe-subcommand>", False),
]
@pytest.mark.parametrize("command,expected", TESTS)
def test_command(check, command: str, expected: bool):
result = check(command)
if expected:
assert is_approved(result), f"Expected approve: {command}"
else:
assert needs_confirmation(result), f"Expected confirm: {command}"创建文件:
tests/cli/test_$ARGUMENTS.pypython
"""Test cases for $ARGUMENTS."""
import pytest
from conftest import is_approved, needs_confirmation
TESTS = [
# Safe operations
("$ARGUMENTS <safe-subcommand>", True),
("$ARGUMENTS --help", True),
# Unsafe operations
("$ARGUMENTS <unsafe-subcommand>", False),
]
@pytest.mark.parametrize("command,expected", TESTS)
def test_command(check, command: str, expected: bool):
result = check(command)
if expected:
assert is_approved(result), f"Expected approve: {command}"
else:
assert needs_confirmation(result), f"Expected confirm: {command}"4. Implement Handler
4. 实现Handler
Create :
src/dippy/cli/$ARGUMENTS.pypython
"""$ARGUMENTS handler for Dippy."""
from dippy.cli import Classification, HandlerContext
COMMANDS = ["$ARGUMENTS"]
SAFE_ACTIONS = frozenset({"list", "show", "status"})
def classify(ctx: HandlerContext) -> Classification:
tokens = ctx.tokens
action = tokens[1] if len(tokens) > 1 else None
if action in SAFE_ACTIONS:
return Classification("allow", description=f"$ARGUMENTS {action}")
return Classification("ask", description="$ARGUMENTS")For handler patterns (nested subcommands, flag-checking, delegation), see patterns.md.
创建文件:
src/dippy/cli/$ARGUMENTS.pypython
"""$ARGUMENTS handler for Dippy."""
from dippy.cli import Classification, HandlerContext
COMMANDS = ["$ARGUMENTS"]
SAFE_ACTIONS = frozenset({"list", "show", "status"})
def classify(ctx: HandlerContext) -> Classification:
tokens = ctx.tokens
action = tokens[1] if len(tokens) > 1 else None
if action in SAFE_ACTIONS:
return Classification("allow", description=f"$ARGUMENTS {action}")
return Classification("ask", description="$ARGUMENTS")如需了解handler模式(嵌套子命令、标识检查、委托),请参阅patterns.md。
5. Iterate
5. 迭代
just testFix failures until tests pass.
just test修复失败的用例,直到所有测试通过。
6. Verify
6. 验证
just check完成开发前必须确保运行通过。
just check