From 863378408d8c1de5783a3b64ace66d9e337d012f Mon Sep 17 00:00:00 2001 From: Brian Kroth Date: Wed, 6 Sep 2023 14:06:23 -0500 Subject: [PATCH] basic powershell support --- licenseheaders.py | 12 ++++++++++++ tests/expected/test.ps1 | 26 ++++++++++++++++++++++++++ tests/input/test.ps1 | 6 ++++++ 3 files changed, 44 insertions(+) create mode 100644 tests/expected/test.ps1 create mode 100644 tests/input/test.ps1 diff --git a/licenseheaders.py b/licenseheaders.py index 088eb43..f8befef 100644 --- a/licenseheaders.py +++ b/licenseheaders.py @@ -101,6 +101,18 @@ def update_c_style_comments(extensions): "headerLinePrefix": "## ", "headerLineSuffix": None }, + "powershell": { + "extensions": [".ps1", ".psm"], + "keepFirst": re.compile(r'^#Requires'), + "blockCommentStartPattern": re.compile(r'<#'), + "blockCommentEndPattern": re.compile(r'#>'), + "lineCommentStartPattern": re.compile(r'^\s*#'), + "lineCommentEndPattern": None, + "headerStartLine": "#\n", + "headerEndLine": "#\n", + "headerLinePrefix": "# ", + "headerLineSuffix": None + }, "python": { "extensions": [".py"], "keepFirst": re.compile(r'^#!|^# +pylint|^# +-\*-|^# +coding|^# +encoding|^# +type|^# +flake8'), diff --git a/tests/expected/test.ps1 b/tests/expected/test.ps1 new file mode 100644 index 0000000..47cf2ca --- /dev/null +++ b/tests/expected/test.ps1 @@ -0,0 +1,26 @@ +#Requires -Version 7 +# +# Copyright (c) 2012-2014 ThisNiceCompany. +# +# This file is part of ProjectName +# (see http://the.projectname.com). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program. If not, see . +# + +<# +Block comment stays here. +#> +# Print some environment variables. +Get-ChildItem -Recurse Env:\ diff --git a/tests/input/test.ps1 b/tests/input/test.ps1 new file mode 100644 index 0000000..d61b4c1 --- /dev/null +++ b/tests/input/test.ps1 @@ -0,0 +1,6 @@ +#Requires -Version 7 +<# +Block comment stays here. +#> +# Print some environment variables. +Get-ChildItem -Recurse Env:\