chef 设置 scope 能力

This commit is contained in:
Aoran Zeng
2026-02-22 22:33:35 +08:00
parent 126fefa528
commit 740d19f0b7
2 changed files with 63 additions and 1 deletions

View File

@@ -285,6 +285,63 @@ chef_deny_english (Target_t *target)
}
/**
* @brief 设置该 target 的作用域能力
*/
void
chef_set_scope_cap (Target_t *target, Scope_t scope, ScopeCapability_t cap)
{
xy_cant_be_null (target);
/* 我们在这里固定好索引的位置,而不是直接用 enum 的值,防止以后顺序或者新增枚举值 */
if (scope == ProjectScope)
{
target->scope_caps[0] = cap;
}
else if (scope == UserScope)
{
target->scope_caps[1] = cap;
}
else if (scope == SystemScope)
{
target->scope_caps[2] = cap;
}
else
{
chsrc_panic ("无效的 scope 参数");
}
}
/**
* @brief 设置该 target 的默认作用域
*
* @note 该函数必须在 chef_set_scope_cap() 之后调用,以确保默认作用域的能力已经被明确了
*/
void
chef_set_default_scope (Target_t *target, Scope_t scope)
{
xy_cant_be_null (target);
target->default_scope = scope;
ScopeCapability_t cap = ScopeCap_Unknown;
if (scope == ProjectScope)
cap = target->scope_caps[0];
else if (scope == UserScope)
cap = target->scope_caps[1];
else if (scope == SystemScope)
cap = target->scope_caps[2];
/* 防止 chef 们写错 */
if (cap != ScopeCap_Able_And_Implemented)
{
chsrc_panic ("该作用域未被明确支持,无法设置为默认作用域");
}
}
void
chef_allow_local_mode (Target_t *target, Capability_t cap, const char *explain_zh, const char *explain_en)
{

View File

@@ -6,7 +6,7 @@
* Contributors : Mikachu2333 <mikachu.23333@zohomail.com>
* |
* Created On : <2024-08-09>
* Last Modified : <2025-08-22>
* Last Modified : <2026-02-22>
* -------------------------------------------------------------
* 本文件作为一个通用模板:
*
@@ -72,6 +72,11 @@ void
chef_allow_local_mode (this, PartiallyCan, "具体说明是否支持项目级换源...", "Tell users the local mode support");
chef_set_scope_cap (this, ProjectScope, ScopeCap_Able_And_Implemented);
chef_set_scope_cap (this, UserScope, ScopeCap_Able_But_NotImplemented);
chef_set_scope_cap (this, SystemScope, ScopeCap_Unable);
chef_set_default_scope (this, UserScope);
// chef_allow_english(this); // 项目是否支持英文
chef_deny_english(this);