在这里,我们将给大家分享关于利用PowerShell截取Checkstyle关于bSpell拼写检查的当前错误行的源文件内容的知识,同时也会涉及到如何更有效地aspell拼写检查、cmd下载文件(利用
在这里,我们将给大家分享关于利用PowerShell截取Checkstyle关于bSpell拼写检查的当前错误行的源文件内容的知识,同时也会涉及到如何更有效地aspell拼写检查、cmd下载文件(利用powershell)、How to Check your PowerShell Version (All the Ways!)、Kubernetes powershell 模块的 Powershell cmdlet 参考的内容。
本文目录一览:- 利用PowerShell截取Checkstyle关于bSpell拼写检查的当前错误行的源文件内容
- aspell拼写检查
- cmd下载文件(利用powershell)
- How to Check your PowerShell Version (All the Ways!)
- Kubernetes powershell 模块的 Powershell cmdlet 参考
利用PowerShell截取Checkstyle关于bSpell拼写检查的当前错误行的源文件内容
== ps1 ==
function go{
$gbk = [System.Text.Encoding]::GetEncoding("GBK")
$utf8 = [System.Text.Encoding]::UTF8
$result = ''spell-filter.txt''
$encoding = [System.Text.Encoding]::GetEncoding("GBK")
rm $result -ea SilentlyContinue
$xml = cat checkstyle.xml
$xml = [xml]$xml # 类型转换
$xml.checkstyle.file|%{$_.error}|?{$_.source -match ''SpellCheck''}|
%{
$fileContent = cat $_.parentNode.name -total $_.line -ea SilentlyContinue # 文件有可能不存在,所以要【静音】
$word = (($_.message -replace ''The Spelling of word '', '''') -replace ''may be illegal. .*'', '''') # 错误的拼写内容
if ($fileContent -ne $Null){
$code = $gbk.GetBytes($fileContent[-1]) # 错误的代码行
$code = $utf8.GetString($code)
''文件: '' + $_.parentNode.name + '' ,行号:'' + $_.line + '' ,拼写错误:'' + $word + '' ,代码:'' + $code>> $result
}else{
''不存在的文件: '' + $_.parentNode.name + '' , '' + $_.line + '' , '' + $word
}
}
}
go
== checkstyle.xml ==
<?xml version="1.0" encoding="UTF-8"?>
<checkstyle version="5.0">
<file name="package_zh_CN.properties">
<error line="114" column="81" severity="error" message="The Spelling of word "pageing" may be illegal. The suggestion(s) include(s): [paging, ageing, panging, pugging, pegging]" source="SpellCheck"/>
<error line="117" column="84" severity="error" message="The Spelling of word "pageing" may be illegal. The suggestion(s) include(s): [paging, ageing, panging, pugging, pegging]" source="SpellCheck"/>
</file>
<file name="addOrDel.js">
<error line="1" severity="info" message="File length is 2,373 lines (max allowed is 2,000)." source="com.puppycrawl.tools.checkstyle.checks.sizes.FileLengthCheck"/>
</file>
<file name="showDataDictDetail.jsp">
<error line="10" column="19" severity="error" message="The Spelling of word "stylesheet" may be illegal. The suggestion(s) include(s): [StyleSheet]" source="SpellCheck"/>
</file>
</checkstyle>
aspell拼写检查
作为一个程序员,尤其是非英语母语国家(ESL or EFL)的程序员,写出漂亮的注释可能要比写出漂亮的代码更难。就比如 Eric 的“来自英语母语国家的”女友就有 “Programmers are English-challenged.“ 的评论。
那么如何在程序的注释中避免犯一些低级语法或者拼写错误呢?Eric 也在 Some useful tools for you to write English articles on Linux 中推荐了几个小工具。我这里算拾人牙慧,稍微写一点儿我非常欣赏的 Aspell 拼写检查工具。
Aspell 是一个强大的拼写检查工具,尤其是对于程序员来说。在 Linux 下,大部分程序员应该是用 Vim 或者 Emacs 写代码,它们有内建拼写检查功能,比如 vim 可以用 :setlocal spell spelllang=en_us 开启对美式英语的拼写检查。不过很少人会安装或者使用拼写检查功能,不是每个人都喜欢写代码时面对一堆高亮的词组(当它们不仅检查注释时,哦,天那!)。幸运的是,我们有 Aspell。
Aspell 使用方法非常简单,比如只想检查 C 或者 C++ 风格的注释和字符串中的拼写错误,就可以用这样的命令:
$ aspell --mode=ccpp -c test.cpp
终端里就会列出一个一个注释中的错误,并给出修改意见。接下来的工作就很简单了,按照窗口下面每个键对应的功能,选择更换单词或者忽略该单词。如下图所示:
Aspell 还有更多模式,比如检查 HTML, TeX, XML, Perl 等等一些文档或程序中的拼写,更多内容就请看 Aspell 的帮助吧。
Aspell 的用户习惯保存在 ~/.aspell.en.prepl 和 ~/.aspell.en.pws 两个用户自定义替换和忽略单词列表里,可以通过备份或者修改这两个列表来改变 aspell 对某些单词拼写检查的策略。
cmd下载文件(利用powershell)
在cmd里依次输入:
1 start powershell 2 $client = new-object System.Net.WebClient 3 $client.DownloadFile(‘X‘,‘Y‘)
X:填文件下载地址
Y:填写下载的保存路径及文件名
演示:
How to Check your PowerShell Version (All the Ways!)
In PowerShell,there are a zillion ways to do the same thing (or close to it). In this blog post,you'll learn every way check your PowerShell version on local and remote computers. We'll cover the bad ways and my recommended way.
If you'd like to go from PowerShell newbie to PowerShell guru,I recommend devouring this FREE mini-course on building a PowerShell tool. This is a step-by-step tutorial with full explanations and guidance from Adam the Automator!
There are websites that show varIoUs ways to check the version of PowerShell. But none that compiled a comprehensive list of all them. I decided to change that.
All these ways should work in both Windows PowerShell and PowerShell Core. These methods should also work in Windows PowerShell versions 1.0 all the way up to PowerShell 7.
The ways you can find out a version of PowerShell you're running are:
- The (Get-Host).Version property
- The $host.Version property
- The registry (Windows PowerShell only)
- The $PsversionTable.Psversion property
Let's break down all the ways to find the version of PowerShell from least to most recommended way.
Get-Host
PowerShell has a concept kNown as hosts. A host is a program that is hosting the PowerShell engine. It is not the PowerShell engine itself.The PowerShell console or a code editor with an integrated terminal are PowerShell hosts.
A host can have a version that is completely independent of PowerShell itself. This can be deceiving to many newcomers. Let me show you why.
If you run (Get-Host).Version,you'll see that it returns a version number that looks like it Could be the PowerShell engine version. Looks can be deceiving.
Below I've ran Get-Host on Windows PowerShell 5.1 and you can see it comes back with 5.1.17134.858. This looks like a legitimate version.
PS51> (Get-Host).Version
Major Minor Build Revision
----- ----- ----- --------
5 1 17134 858
copy
However,sometimes when you run Get-Host in an integrated terminal,the version is not the same. Although usually the host will represent the same version of the engine,it doesn't necessary always do that.
Get-Host on Remote Computers
Even though Get-Host seems to return the same version when run on a local computer,it never will on remote computers.
For example,let's run Get-Host on a remote Windows Server 2016 server via Invoke-Command and see what happens.
PS51> Invoke-Command -ComputerName 10.0.0.5 -ScriptBlock {(Get-Host} -Credential $cred
Major Minor Build Revision PSComputerName
----- ----- ----- -------- --------------
1 0 0 0 10.0.0.5
copy
The last time I checked,it's not possible to run PowerShell v1 on Windows Server 2016.
Relying on Get-Host is just a bad idea all around.
$host.Version
Referencing $host.Version is another way to check the version. The $host variable is an automatic variable that returns the same output as Get-Host.
There's nothing special about this method. It's simply the same as running Get-Host.
$host.Version on Remote Computers
You will see the same behavior via PowerShell Remoting with $host.Version as you will running Get-Host.
PS51> Invoke-Command -ComputerName 10.0.0.5 -ScriptBlock {$host.Version} -Credential $cred
Major Minor Build Revision PSComputerName
----- ----- ----- -------- --------------
1 0 0 0 10.0.0.5
copy
Danger,Will Robinson!
Registry
If you don't want to open up PowerShell itself,you can also check the registry. The version of PowerShell is tucked away under a value in the registry key path HKLM:\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine. This registry key has a value called PowerShellVersion that you can reference by using Get-ItemProperty.
PS51> (Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine -Name 'PowerShellVersion').PowerShellVersion
5.1.17134.1
copy
You can see that this version is similar but doesn't include the revision like the other options do.
PS51> [version](Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine -Name 'PowerShellVersion').PowerShellVersion
Major Minor Build Revision
----- ----- ----- --------
5 1 17134 1
copy
Using Other Tools
Using the registry also means you don't need to use PowerShell at all to find the version. You can run commands from the command prompt or another tool that can read the registry.
CMD> reg query HKLM\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine /v PowerShellVersion
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine
PowerShellVersion REG_SZ 5.1.17134.1
Registry on Remote Computers
The registry is static and the values won't change locally or remotely. You can be confident that what you see locally will be the same as you see remotely.
PS51> $scriptBlock = {
[version](Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine -Name 'PowerShellVersion').PowerShellVersion
}
PS51> Invoke-Command -ComputerName 10.0.0.5 -ScriptBlock $scriptBlock -Credential $cred
Major Minor Build Revision PSComputerName
----- ----- ----- -------- --------------
5 1 17763 1 10.0.0.5
copy
Showing the same version locally and remotely is good. But I've got a better way to show you using the $PsversionTable automatic variable.
$PsversionTable.Psversion
The last and final method is referencing the Psversion property on the $PsversionTable automatic variable. This method will always represent the PowerShell engine.
PS51> $PsversionTable.Psversion
Major Minor Build Revision
----- ----- ----- --------
5 1 17134 858
copy
The $PsversionTable automatic variable is a read-only hash table that returns information specifically about the PowerShell engin version. This automatic variable not only returns the version but also PSEdition. This property can either Core or Desktop to provide further information on the edition of PowerShell that is running.
$PsversionTable on Remote Computers
Using the $PsversionTable automatic variable is accurate locally as it is remotely. You can see below that by wrapping $PsversionTable.Psversion in a scriptblock and executing that code on a remote computer,it will return the same version.
PS C:\> Invoke-Command -ComputerName 10.0.0.5 -ScriptBlock {$PsversionTable.Psversion} -Credential $cred
Major Minor Build Revision PSComputerName
----- ----- ----- -------- --------------
5 1 17763 592 10.0.0.5
copy
Summary
In this blog post,you have learned all of the ways to check the version of PowerShell both locally and remotely. I hope the first few methods gave you an idea on which ways not to check the version!
I recommend always using $PsversionTable.Psversion. All of the other methods may appear similar to the PowerShell engine version but may not always reflect the engine version.
If I missed any way,please let me kNow in the comments. I'll be glad to update the post and give you credit.
Kubernetes powershell 模块的 Powershell cmdlet 参考
如何解决Kubernetes powershell 模块的 Powershell cmdlet 参考?
在哪里可以看到 k8s 模块 here 的 cmdlet 参考?
谢谢
解决方法
这是为了更好的可见性而发布的社区 wiki 答案。
正如评论中已经提到的,您正在寻找的参考资料可以在 here(module page 左侧的 Project Site
链接)中找到。
关于利用PowerShell截取Checkstyle关于bSpell拼写检查的当前错误行的源文件内容的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于aspell拼写检查、cmd下载文件(利用powershell)、How to Check your PowerShell Version (All the Ways!)、Kubernetes powershell 模块的 Powershell cmdlet 参考等相关知识的信息别忘了在本站进行查找喔。
本文标签: