Skip to content

Commit

Permalink
0.4.0-preview
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhitsolutions committed Apr 22, 2021
1 parent f175f34 commit a6a8486
Show file tree
Hide file tree
Showing 13 changed files with 1,140 additions and 20 deletions.
8 changes: 8 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# ChangeLog for PSFunctionInfo

## 0.4.0

+ Added `Set-PSFunctionInfoDefaults` and `Get-PSFunctionInfoDefaults` to store default values. The defaults are stored in a JSON file at `$home\psfunctioninfo-defaults.json`. If the file is found when the module is imported, it will be used to set $PSDefaultParameterValues for this module.
+ Added `Update-PSFunctionInfoDefaults` which can be used to update defaults if they are changed after the module has been loaded.
+ Added `about_PSFunctionInfo` help.
+ Minor help updates.
+ Updated `README.md`.

## 0.3.0

+ Added online help links.
Expand Down
Binary file modified PSFunctionInfo.psd1
Binary file not shown.
10 changes: 9 additions & 1 deletion PSFunctionInfo.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@ Get-ChildItem $PSScriptRoot\functions\*.ps1 | ForEach-Object {
. $_.FullName
}

#load defaults if found
$defaults = Join-Path $home -ChildPath psfunctioninfo-defaults.json
if (Test-Path -path $defaults) {
$d = Get-Content -Path $defaults | ConvertFrom-JSON
$d.psobject.properties | Foreach-Object {
$global:PSDefaultParameterValues["New-PSFunctionInfo:$($_.name)"] = $_.value
}
}

#create an argument completer
Register-ArgumentCompleter -CommandName Get-PSFunctionInfo -ParameterName Name -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)

#PowerShell code to populate $wordtoComplete
Get-Childitem -path Function:\$wordToComplete* |
ForEach-Object {
# completion text,listitem text,result type,Tooltip
Expand Down
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,26 @@ Source C:\scripts\FooStuff.ps1

There are no commands to modify or remove function metadata. It is assumed that when you update the function, you can update or remove the metadata.

## PSFunctionInfo Defaults

Because you might define function metadata often, and want to maintain consistency, you can define a set of default values for `New-PSFunctionInfo`. Use the command, `Set-PSFunctionInfoDefaults`:

```powershell
Set-PSFunctionInfoDefaults -Tags "stand-alone" -Copyright "(c) JDH IT Solutions, Inc." -author "Jeff Hicks" -company "JDH IT Solutions, Inc."
```

The defaults will be stored in a JSON file at `$home\psfunctioninfo-defaults.json`. When you import this module, these values will be used to define entries in `$PSDefaultParameterValues`. Or, run `Update-PSFunctionInfoDefaults` to update parameter defaults.

You can use `Get-PSFunctionInfoDefaults` to see the current values.

## Background

This code is a prototype for a [suggestion](https://github.com/PowerShell/PowerShell/issues/11667) I made for PowerShell 7. Early versions of this code were published as [https://gist.github.com/jdhitsolutions/65070cd51b5cfb572bc6375f67bcbc3d](https://gist.github.com/jdhitsolutions/65070cd51b5cfb572bc6375f67bcbc3d "view the Github gist")

## Roadmap

+ Add VS Code integration
+ Extract function metadata from files directly
+ Add VS Code integration.
+ Extract function metadata from files directly.
+ Add function metadata by file, autodetecting the function name.

Last Updated 2021-04-21 15:57:36Z
Last Updated 2021-04-22 13:04:23Z
2 changes: 1 addition & 1 deletion docs/Get-PSFunctionInfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ Aliases:

Required: False
Position: 0
Default value: None
Default value: *
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: False
```
Expand Down
61 changes: 61 additions & 0 deletions docs/Get-PSFunctionInfoDefaults.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
external help file: PSFunctionInfo-help.xml
Module Name: PSFunctionInfo
online version:
schema: 2.0.0
---

# Get-PSFunctionInfoDefaults

## SYNOPSIS

Get defined PSFunctionInfo defaults.

## SYNTAX

```yaml
Get-PSFunctionInfoDefaults [<CommonParameters>]
```

## DESCRIPTION

You can store default values for PSFunctionInfo commands using Set-PSFunctionInfoDefaults. The data is stored in a JSON file at $home\psfunctioninfo-defaults.json. Use Get-PSFunctionInfoDefaults to view.

## EXAMPLES

### Example 1

```powershell
PS C:\> Get-PSFunctionInfoDefaults
Version : 0.9.0
CompanyName : JDH IT Solutions, Inc.
Author : Jeffery Hicks
Tags : {stand-alone}
Copyright : (c) JDH IT Solutions, Inc.
```

## PARAMETERS

### CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).

## INPUTS

### None

## OUTPUTS

### PSFunctionInfoDefault

## NOTES

Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/

## RELATED LINKS

[Set-PSFunctionInfoDefaults](Set-PSFunctionInfoDefaults.md)

[Update-PSFunctionInfoDefaults](Update-PSFunctionInfoDefaults.md)
6 changes: 3 additions & 3 deletions docs/New-PSFunctionInfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ New-PSFunctionInfo [-Name] <String> -Path <String> [-Author <String>] [-CompanyN

This command will create a function metadata comment block and insert it into the source script file. Or you can copy it to the clipboard and insert it yourself. There are no commands to modify or remove the function metatdata once it has been inserted into the file. It is assumed that if you update the function, you can manually update (or remove) the metadata at the same time.

NOTE: This command will not work properly with one-line function declarations like Function Get-This { Get-Date }.
NOTE: This command will not work properly with one-line function declarations like Function Get-This { Get-Date }. It is also expected that you don't have multiple versions of the function in the same file.

Do not modify spacing or formatting of the function metadata.

Expand Down Expand Up @@ -125,7 +125,7 @@ Aliases:

Required: False
Position: Named
Default value: None
Default value: the current year
Accept pipeline input: False
Accept wildcard characters: False
```
Expand Down Expand Up @@ -180,7 +180,7 @@ Accept wildcard characters: False
### -Path
Specify the path to the .ps1 file that contains the function.
Specify the path to the .ps1 file that contains the function. The path must end in .ps1.
```yaml
Type: String
Expand Down
170 changes: 170 additions & 0 deletions docs/Set-PSFunctionInfoDefaults.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
---
external help file: PSFunctionInfo-help.xml
Module Name: PSFunctionInfo
online version:
schema: 2.0.0
---

# Set-PSFunctionInfoDefaults

## SYNOPSIS

Store default values for PSFunctionInfo commands.

## SYNTAX

```yaml
Set-PSFunctionInfoDefaults [[-Author] <String>] [[-CompanyName] <String>]
[[-Copyright] <String>] [[-Version] <String>] [[-Tags] <String[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

## DESCRIPTION

Because you might define function metadata often, and want to maintain consistency, you can define a set of default values for New-PSFunctionInfo. Set-PSFunctionInfoDefaults will create a JSON file at $home\psfunctioninfo-defaults.json. When you import this module, these values will be used to define entries in $PSDefaultParameterValues. Or, run Update-PSFunctionInfoDefaults to update parameter defaults.

## EXAMPLES

### Example 1

```powershell
PS C:\> Set-PSFunctionInfoDefaults -Copyright "(c) JDH IT Solutions, Inc." -author "Jeff Hicks" -company "JDH IT Solutions, Inc."
```

## PARAMETERS

### -Author

Enter the default author name.

```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 0
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -CompanyName
Enter the default company name.
```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 1
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -Confirm
Prompts you for confirmation before running the cmdlet.
```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases: cf

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Copyright
Enter the default copyright string.
```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 2
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -Tags
Enter the default tag(s).
```yaml
Type: String[]
Parameter Sets: (All)
Aliases:

Required: False
Position: 4
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -Version
Enter the default version.
```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 3
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -WhatIf
Shows what would happen if the cmdlet runs.
The cmdlet is not run.
```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases: wi

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
## INPUTS
### System.String
### System.String[]
## OUTPUTS
### None
## NOTES
Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/
## RELATED LINKS
[Get-PSFunctionInfoDefaults](Get-PSFunctionInfoDefaults.md)
[Update-PSFunctionInfoDefaults](Update-PSFunctionInfoDefaults.md)
Loading

0 comments on commit a6a8486

Please sign in to comment.