“排序"的替代方法作为 PowerShell 动词? [英] Alternative to "Sort" as a PowerShell verb?

查看:37
本文介绍了“排序"的替代方法作为 PowerShell 动词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 PowerShell 函数 Sort-VersionLabels.当我将此功能添加到模块时,Import-Module 抱怨:

I have a PowerShell function Sort-VersionLabels. When I add this function to a module, Import-Module complains:

WARNING: Some imported command names include unapproved verbs which might make 
them less discoverable.  Use the Verbose parameter for more detail or type
Get-Verb to see the list of approved verbs.

根据this, Sort 是一个保留动词".

According to this, Sort is a "reserved verb".

什么是好的(并且被认可的)替代方案?

What could be a good (and approved) alternative?

更新
该函数采用以下形式的版本号数组:..[-].里程碑可以是 devalphabetastable(按此顺序).所以标准的 Sort-Object 函数将不起作用.

Update
The function takes a array of version numbers in the form: <major>.<minor>.<revision>[-<milestone[nr]>]. Milestone can be dev, alpha, beta or stable (in that order). So the standard Sort-Object function won't work.

将排序后的数组输出到管道.

It outputs the sorted array to the pipe line.

推荐答案

这个问题的核心会产生自以为是的结果.这造成了一个难题,因为您正在寻找当前答案无法解决的特定问题.我知道您正在寻找一种在逻辑上适合您的功能同时位于标准动词列表中的解决方案,这是令人钦佩的.继续我之前发表的评论,我将尝试为所有可能适合您情况的已批准动词陈述一个案例.我会经常参考您的问题中链接的批准的动词列表,并会使用AVL"为简洁起见.

The core of this issue will generate opinionated results. This creates a conundrum since you are looking for something specific that the current answers have been unable to address. I understand that you are looking for a solution that logically fits your function while being in the standard verb list, which is admirable. To continue from an earlier comment I made I am going to try and state a case for all the approved verbs that might fit your situation. I will refer to the Approved Verbs List linked in your question frequently and will use "AVL" for brevity going forward.

  1. Group:对 AVL 的评论是指使用它代替排列.安排成为 Sort 的同义词将是一个很好的选择.坚持建议,然后我们应该使用 Group
  2. Set:它是排序的同义词.但是,在 AVL 中,它与与您的 cmdlet 无关的 Write、Reset、Assign 或 Configure 相关联.尽管如此,它仍然在列表中,如果您愿意搁置它使用现有 PowerShell cmdlet 创建的混乱,它可能适合.
  3. 我真的没有数字 3.
  4. 更新:这是一个弱案例,但 AVL 将其用作保持 [a cmdlet] 状态 [和] 准确性的一种方式.
  5. Order/Organize:不在 AVL 中,但我发现这些非常合适,目前不与任何现有动词发生冲突.
  1. Group: The comments on the AVL refers to using this in place of Arrange. Arrange being a synonym for Sort would be a good fit. Sticking with the recommendation then we should use Group
  2. Set: It is a synonym for Sort. However, in the AVL, it is associated with Write, Reset, Assign, or Configure which are not related to your cmdlet. Still, it is in the list and could fit if you are willing to put aside the discombobulation that it creates with existing PowerShell cmdlets.
  3. I dont really have a number 3.
  4. Update: This is a weak case but the AVL refers its use as a way to maintain [a cmdlets] state [and] accuracy.
  5. Order/Organize: Not in the AVL but I find these very fitting and dont currently conflict with any existing verbs.

最终,该死的 AVL 可以为所欲为.Sort 非常 非常适合您正在尝试做的事情.您也可以在导入模块时使用 -DisableNameChecking.毕竟这只是一个警告.在我看来,Briatist 的回答也很好.

Ultimately, AVL be damned and do whatever you want. Sort is a very good fit for what you are trying to do. You can also just use -DisableNameChecking when importing your module. It is only a warning after all. Briatist's answer is also good in my opinion.

评论奖励

不是您要求它,而是当您说我们必须启用名称检查时,我想到了这一点.仅供娱乐!

Not that you asked for it, but when you said we have to enable name checking I thought about this. Just for fun!

$reservedVerbs = "ForEach","Format","Group","Sort","Tee"
$approvedVerbList = (Get-Verb).Verb

Get-Command -Module  Microsoft.WSMan.Management | ForEach-Object{
    If ($approvedVerbList -notcontains ($_.Name -split "-")[0]){
        Write-Warning "$($_.Name) does not use an approved verb."
    }

    If ($reservedVerbs -contains ($_.Name -split "-")[0]){
        Write-Warning "$($_.Name) is using a reserved verb."
    }
}

这篇关于“排序"的替代方法作为 PowerShell 动词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆