Skip to content

Commit 9f68676

Browse files
committed
dont execute asjob with nowait
1 parent 25eccaa commit 9f68676

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

src/Common/Extensions/CmdletExtensions.cs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,6 @@ public static Job ExecuteAsJob<T>(this T cmdlet, string jobName, Action<T> execu
7171
return job;
7272
}
7373

74-
/// <summary>
75-
/// Determine if AsJob is present
76-
/// </summary>
77-
/// <typeparam name="T">The cmdlet type</typeparam>
78-
/// <param name="cmdlet">The cmdlet</param>
79-
/// <returns>True if the cmdlet shoudl run as a Job, otherwise false</returns>
80-
public static bool AsJobPresent<T>(this T cmdlet) where T : AzurePSCmdlet
81-
{
82-
if (cmdlet == null)
83-
{
84-
throw new ArgumentNullException(nameof(cmdlet));
85-
}
86-
87-
return (cmdlet.MyInvocation?.BoundParameters != null
88-
&& cmdlet.MyInvocation.BoundParameters.ContainsKey("AsJob"));
89-
}
90-
9174
/// <summary>
9275
/// Execute the given cmdlet synchronously os as a job, based on input parameters
9376
/// </summary>
@@ -121,7 +104,8 @@ public static void ExecuteSynchronouslyOrAsJob<T>(this T cmdlet, Action<T> execu
121104
throw new ArgumentNullException(nameof(executor));
122105
}
123106

124-
if (cmdlet.AsJobPresent())
107+
// Since right now NoWait and AsJob are not in different parameter sets this check is necessary
108+
if (cmdlet.IsBound("AsJob") && !cmdlet.IsBound("NoWait"))
125109
{
126110
cmdlet.WriteObject(cmdlet.ExecuteAsJob(cmdlet.ImplementationBackgroundJobDescription, executor));
127111
}
@@ -212,7 +196,7 @@ public static void SafeCopyParameterSet<T>(this T source, T target) where T : Az
212196
/// <returns>true if the parameter was provided by the user, otherwise false</returns>
213197
public static bool IsBound(this PSCmdlet cmdlet, string parameterName)
214198
{
215-
return cmdlet.MyInvocation.BoundParameters.ContainsKey(parameterName);
199+
return cmdlet.MyInvocation?.BoundParameters.ContainsKey(parameterName) ?? false;
216200
}
217201

218202
public static string AsAbsoluteLocation(this string realtivePath)
@@ -358,7 +342,7 @@ public static List<T> ExecuteScript<T>(this PSCmdlet cmdlet, string contents)
358342
public static bool IsParameterBound<TPSCmdlet, TProp>(this TPSCmdlet cmdlet, Expression<Func<TPSCmdlet, TProp>> propertySelector) where TPSCmdlet : PSCmdlet
359343
{
360344
var propName = ((MemberExpression)propertySelector.Body).Member.Name;
361-
return cmdlet.MyInvocation.BoundParameters.ContainsKey(propName);
345+
return cmdlet.MyInvocation?.BoundParameters.ContainsKey(propName) ?? false;
362346
}
363347

364348
#region PowerShell Commands

0 commit comments

Comments
 (0)