-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Python Import.py Template ( Fixes #913 )
- Loading branch information
James Brundage
committed
Feb 15, 2024
1 parent
bbd354f
commit 657ff0a
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
Template function Import.py { | ||
<# | ||
.SYNOPSIS | ||
Python Import Template | ||
.DESCRIPTION | ||
Template for Import statements in Python | ||
.EXAMPLE | ||
Template.Import.py -ModuleName sys | ||
.EXAMPLE | ||
'sys','json' | Template.Import.py -As { $_[0] } | ||
#> | ||
[Alias('Import.py','Require.py','Imports.py','Requires.py','Includes.py')] | ||
param( | ||
# The name of one or more libraries to import. | ||
[vbn(ValueFromPipeline)] | ||
[Alias('LibraryName','PackageName')] | ||
[string[]] | ||
$ModuleName, | ||
|
||
# The name of one or more functions to import from the module | ||
[vbn()] | ||
[Alias('From')] | ||
[string] | ||
$Function, | ||
|
||
# The alias for the imported type or function. | ||
[vbn()] | ||
[Alias('Alias')] | ||
[string] | ||
$As | ||
) | ||
|
||
process { | ||
@" | ||
$(if ($Function) { | ||
"from$($ModuleName -join ',') import $($functionName -join ",")$(if ($As) {" as $As"})" | ||
} elseif ($As) { | ||
"import $($ModuleName -join ',') as $As" | ||
} else { | ||
"import $($ModuleName -join ',')" | ||
}) | ||
"@ | ||
} | ||
} |