@@ -25,24 +25,23 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands
2525 public class InvokeFormatterCommand : PSCmdlet , IOutputWriter
2626 {
2727 private const string defaultSettingsPreset = "CodeFormatting" ;
28- private Settings defaultSettings ;
2928 private Settings inputSettings ;
3029
3130 /// <summary>
3231 /// The script text to be formated.
3332 ///
3433 /// *NOTE*: Unlike ScriptBlock parameter, the ScriptDefinition parameter require a string value.
3534 /// </summary>
36- [ ParameterAttribute ( Mandatory = true ) ]
35+ [ ParameterAttribute ( Mandatory = true , Position = 1 ) ]
3736 [ ValidateNotNull ]
3837 public string ScriptDefinition { get ; set ; }
3938
4039 /// <summary>
4140 /// A settings hashtable or a path to a PowerShell data file (.psd1) file that contains the settings.
4241 /// </summary>
43- [ Parameter ( Mandatory = false ) ]
42+ [ Parameter ( Mandatory = false , Position = 2 ) ]
4443 [ ValidateNotNull ]
45- public object Settings { get ; set ; }
44+ public object Settings { get ; set ; } = defaultSettingsPreset ;
4645
4746#if DEBUG
4847 [ Parameter ( Mandatory = false ) ]
@@ -88,18 +87,26 @@ protected override void BeginProcessing()
8887
8988 try
9089 {
91- inputSettings = PSSASettings . Create ( Settings , null , this ) ;
92- if ( inputSettings == null )
93- {
94- inputSettings = new PSSASettings (
95- defaultSettingsPreset ,
96- PSSASettings . GetSettingPresetFilePath ) ;
97- }
90+ inputSettings = PSSASettings . Create ( Settings , this . MyInvocation . PSScriptRoot , this ) ;
9891 }
99- catch
92+ catch ( Exception e )
93+ {
94+ this . ThrowTerminatingError ( new ErrorRecord (
95+ e ,
96+ "SETTNGS_ERROR" ,
97+ ErrorCategory . InvalidData ,
98+ Settings ) ) ;
99+ }
100+
101+ if ( inputSettings == null )
100102 {
101- this . WriteWarning ( String . Format ( CultureInfo . CurrentCulture , Strings . SettingsNotParsable ) ) ;
102- return ;
103+ this . ThrowTerminatingError ( new ErrorRecord (
104+ new ArgumentException ( String . Format (
105+ CultureInfo . CurrentCulture ,
106+ Strings . SettingsNotParsable ) ) ,
107+ "SETTINGS_ERROR" ,
108+ ErrorCategory . InvalidArgument ,
109+ Settings ) ) ;
103110 }
104111 }
105112
0 commit comments