Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-PSRuleHelp search into the current directory by default #197

Closed
LaurentDardenne opened this issue Jun 19, 2019 · 2 comments · Fixed by #283
Closed

Get-PSRuleHelp search into the current directory by default #197

LaurentDardenne opened this issue Jun 19, 2019 · 2 comments · Fixed by #283
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@LaurentDardenne
Copy link

The cmdlet Get-PSRuleHelp must search into the current directory if the 'Path' parameter has no argument :

cd C:\Prive\PSRule\Rule1
dir -rec

#     Répertoire : C:\Prive\PSRule\Rule1


# Mode                LastWriteTime         Length Name
# ----                -------------         ------ ----
# d-----       19/06/2019     14:45                fr-FR
# -a----       19/06/2019     11:12            371 Test.Rule.ps1


#     Répertoire : C:\Prive\PSRule\Rule1\fr-FR

# Mode                LastWriteTime         Length Name
# ----                -------------         ------ ----
# -a----       19/06/2019     14:42            264 Test.md

One rule file exist into the current directory, but Get-PSRuleHelp do not read it :

Get-PSRuleHelp -Name Test -verbose
# COMMENTAIRES : [Get-PSRuleHelp]::BEGIN
# COMMENTAIRES : [New-PSRuleOption] BEGIN::
# COMMENTAIRES : Attempting to read: C:\Prive\PSRule\Rule1
# COMMENTAIRES : [New-PSRuleOption] END::
# COMMENTAIRES : [PSRule][D] -- Found 0 PSRule module(s)
# COMMENTAIRES : [Get-PSRuleHelp] -- Could not find any .Rule.ps1 script files in the path
# COMMENTAIRES : [Get-PSRuleHelp]::END

When I specify the 'Path' parameter with a relative path, it finds the help file

Get-PSRuleHelp -Name Test -Path .\Test.Rule.ps1 -verbose
# COMMENTAIRES : [Get-PSRuleHelp]::BEGIN
# COMMENTAIRES : [New-PSRuleOption] BEGIN::
# COMMENTAIRES : Attempting to read: C:\Prive\PSRule\Rule1
# COMMENTAIRES : [New-PSRuleOption] END::
# COMMENTAIRES : [PSRule][D] -- Scanning for source files: .\Test.Rule.ps1
# COMMENTAIRES : [PSRule][D] -- Found 0 PSRule module(s)
# COMMENTAIRES : [Get-PSRuleHelp] -- Found 1 source file(s)
# COMMENTAIRES : [PSRule][D] -- Discovering rules in: C:\Prive\PSRule\Rule1\Test.Rule.ps1
# COMMENTAIRES : [PSRule][D] -- Found Test in C:\Prive\PSRule\Rule1\Test.Rule.ps1
# COMMENTAIRES : [PSRule][D] -- Found Test1 in C:\Prive\PSRule\Rule1\Test.Rule.ps1
# COMMENTAIRES : [PSRule][D] -- Found Test2 in C:\Prive\PSRule\Rule1\Test.Rule.ps1
# COMMENTAIRES : [PSRule][D] -- Found Test3 in C:\Prive\PSRule\Rule1\Test.Rule.ps1
# COMMENTAIRES : [PSRule][D] -- Found Test4 in C:\Prive\PSRule\Rule1\Test.Rule.ps1
# COMMENTAIRES : [PSRule][D] -- Found Test5 in C:\Prive\PSRule\Rule1\Test.Rule.ps1
# COMMENTAIRES : [PSRule][D] -- Found WithDependency2 in C:\Prive\PSRule\Rule1\Test.Rule.ps1
# COMMENTAIRES : [PSRule][D] -- Found WithDependency5 in C:\Prive\PSRule\Rule1\Test.Rule.ps1

# NAME
#     Test

# SYNOPSIS
#     A brief summary of the rule

# DESCRIPTION
#     A detailed description of the rule

# RECOMMENDATION
#     A detailed explanation of the steps required to pass the rule

# COMMENTAIRES : [Get-PSRuleHelp]::END

That said, research in the current path can often be problematic with Powershell :

cd hklm:
Get-PSRuleHelp -Name Test -Path .\Test.Rule.ps1 -verbose
#COMMENTAIRES : [Get-PSRuleHelp]::BEGIN
#COMMENTAIRES : [New-PSRuleOption] BEGIN::
#COMMENTAIRES : Attempting to read: HKLM:\
#Exception lors de l'appel de «FromFile» avec «2» argument(s): «Le format du chemin d'accès donné n'est pas pris en charge.»
#NotSupportedException
...
@BernieWhite BernieWhite added the enhancement New feature or request label Jun 19, 2019
@BernieWhite
Copy link
Member

BernieWhite commented Jun 19, 2019

@LaurentDardenne Yeah, so Get-PSRuleHelp searches rules in loaded modules first. The intent was to match similar functionality to Get-Help.

The reasoning for this was that modules are more likely to have markdown help created for them then standalone rules.

-Path can be used, but it is more explicit.

This this behaviour may be confusing since, most of the other PSRule cmdlets operate on the current working path first.

However i'm interested in your feedback to improve this in the future.

@LaurentDardenne
Copy link
Author

However i'm interested in your feedback to improve this in the future.

According to the documentation:

If the rules are loose (not part of a module), PSRule will search for documentation in the .<culture>\ subdirectory relative to where the rule script .ps1 file is located.

If one is already in the directory of a script of a rule, I think that if Path is not informed one can first search the help file in the current directory before displaying an error s' he does not exist.
I have not yet studied the creation of modules of rule, but already I know one of the advantages.

@BernieWhite BernieWhite changed the title [Feature Request] Get-PSRuleHelp must search into the current directory Get-PSRuleHelp search into the current directory by default Aug 5, 2019
@BernieWhite BernieWhite added this to the v0.9.0 milestone Aug 5, 2019
@BernieWhite BernieWhite self-assigned this Aug 5, 2019
BernieWhite added a commit that referenced this issue Sep 17, 2019
- Added support for matching an array of tag values. #282
- Updated Get-PSRuleHelp to include help within the current path by default. #197
- Fix can not serialize nested System.IO.DirectoryInfo property. #281
- Breaking change: Added named baselines. This changes how baselines work. #274
This was referenced Sep 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants