PowerShell 批准了 "Archive" 和 "Unarchive" 数据项的动词

PowerShell Approved Verbs for "Archive" and "Unarchive" of Data Items

我有支持存档和取消存档的数据,但 Approved Verbs for PowerShell Commands 中的 none 似乎适合用于数据管理或资源生命周期。

从技术上讲,相关数据项实际上在 RESTful API 上可用,并通过 ID 引用。我正在构建的 Cmdlet 说 API。

编辑:这些数据项更准确地描述为记录,归档行为是对处于归档状态的记录进行某种形式的重新分类或重新标记。

哪些动词最合适,选择时应考虑哪些实施因素和注意事项?

New-DataArchiveRemove-DataArchive

不确定底层 API 的细节,但通常有 POST(新)和 DELETE(删除)。

我也非常喜欢在匹配不佳时添加 [Alias]。例如,我最近在 git 领域工作,其中 Fork 是一个众所周知的概念,所以我选择了“最接近”的认可动词,但添加了一个别名以提供清晰度(别名可以是任何你想要)

function Copy-GithubProject {
    [Alias("Fork-GithubProject")]
    [CmdletBinding()]

我认为这归结为 user-experience(使用上述 Cmdlet 的用户)与 actual-implementation。 Approved Verbs for PowerShell Commands 文章在描述动词时主要指的是 actual-implementation,而不是那些使用 Cmdlet 的 user-experience。我认为根据实际实施选择 PowerShell 动词,而不是将其抽象化并专注于 common-sense user-experience,才是应该使用已批准的 PowerShell 动词列表的方式。

Set (s): Replaces data on an existing resource or creates a resource that contains some data...

Get (g): Specifies an action that retrieves a resource. This verb is paired with Set.

虽然用户可能存档了一些东西,但他们实际上可能只是在更改资源上的标签或 archive-bit。在我的例子中,'Archiving' 实际上只是后端数据库上一行的标志,意思是,它是 替换现有资源 上的数据,所以 Set-ArchiveState Seth 建议的(或等效)在这里最合适。

New vs. Set

Use the New verb to create a new resource. Use the Set verb to modify an existing resource, optionally creating it if it does not exist, such as the Set-Variable cmdlet.

...

New (n): Creates a resource. (The Set verb can also be used when creating a resource that includes data, such as the Set-Variable cmdlet.)

我认为 New 仅适用于基于旧资源创建新资源的情况,新资源代表存档副本。在我的 use-case 中,它的资源归档由一个标志表示,我主要更改现有资源上的数据,因此 New 不适合这里。

Publish (pb): Makes a resource available to others. This verb is paired with Unpublish.

Unpublish (ub): Makes a resource unavailable to others. This verb is paired with Publish.

有人认为,如果 Archiving/Unarchiving 限制资源的可用性,Publish/Unpublish 是合适的,但我认为这会对 user-experience 甚至超过 Set/Get 以一种不常见的方式使用术语。

Compress (cm): Compacts the data of a resource. Pairs with Expand.

Expand (en): Restores the data of a resource that has been compressed to its original state. This verb is paired with Compress.

这是非常具体的实现方式,我认为只有当 Archive/Unarchive 操作的主要目的是为了数据压缩而不是资源生命周期管理时才适用。