Skip to content
This repository was archived by the owner on Aug 6, 2019. It is now read-only.

Commit 76b6927

Browse files
Merge branch 'develop'
2 parents 58feaaa + 8de8dbd commit 76b6927

File tree

11 files changed

+181
-114
lines changed

11 files changed

+181
-114
lines changed

Code.Cake/CodeCakeApplication.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public RunResult Run( string[] args, string appRoot = null)
141141
if( !AvailableBuilds.TryGetValue( options.Script, out choosenBuild ) )
142142
{
143143
logger.Error( "Build script '{0}' not found.", options.Script );
144-
return new RunResult( -1, context.IsInteractiveMode(), context.IsAutoInteractiveMode() );
144+
return new RunResult( -1, context.InteractiveMode() );
145145
}
146146

147147
// Set the working directory: the solution directory.
@@ -175,7 +175,7 @@ public RunResult Run( string[] args, string appRoot = null)
175175
{
176176
case CakeTerminationOption.Error:
177177
logger.Error( "Termination with Error: '{0}'.", ex.Message );
178-
return new RunResult( -2, context.IsInteractiveMode(), context.IsAutoInteractiveMode() );
178+
return new RunResult( -2, context.InteractiveMode() );
179179
case CakeTerminationOption.Warning:
180180
logger.Warning( "Termination with Warning: '{0}'.", ex.Message );
181181
break;
@@ -188,14 +188,14 @@ public RunResult Run( string[] args, string appRoot = null)
188188
catch( TargetInvocationException ex )
189189
{
190190
logger.Error( "Error occurred: '{0}'.", ex.InnerException?.Message ?? ex.Message );
191-
return new RunResult( -3, context.IsInteractiveMode(), context.IsAutoInteractiveMode() );
191+
return new RunResult( -3, context.InteractiveMode() );
192192
}
193193
catch( Exception ex )
194194
{
195195
logger.Error( "Error occurred: '{0}'.", ex.Message );
196-
return new RunResult( -4, context.IsInteractiveMode(), context.IsAutoInteractiveMode() );
196+
return new RunResult( -4, context.InteractiveMode() );
197197
}
198-
return new RunResult( 0, context.IsInteractiveMode(), context.IsAutoInteractiveMode() );
198+
return new RunResult( 0, context.InteractiveMode() );
199199
}
200200

201201
/// <summary>

Code.Cake/CodeCakeSpecific/InteractiveAliases.cs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,28 @@ public static class InteractiveAliases
2323
/// </summary>
2424
public static readonly string AutoInteractionArgument = "autointeraction";
2525

26+
27+
/// <summary>
28+
/// Gets the current <see cref="CodeCake.InteractiveMode"/>.
29+
/// </summary>
30+
/// <param name="context">The context.</param>
31+
/// <returns>The mode.</returns>
32+
[CakeAliasCategory( "Interactive mode" )]
33+
[CakeMethodAlias]
34+
public static InteractiveMode InteractiveMode( this ICakeContext context )
35+
{
36+
if( context.HasArgument( NoInteractionArgument ) ) return CodeCake.InteractiveMode.NoInteraction;
37+
if( context.HasArgument( AutoInteractionArgument ) ) return CodeCake.InteractiveMode.AutoInteraction;
38+
return CodeCake.InteractiveMode.NoInteraction;
39+
}
40+
2641
/// <summary>
27-
/// Gets whether the context supports interaction with the user (depends on -nointeraction argument).
42+
/// Gets whether the context requires interaction with the user:
43+
/// False if -nointeraction or -autointeraction argument has been provided, true if no specific argument have been provided.
2844
/// </summary>
2945
/// <param name="context">The context.</param>
3046
/// <returns>True if interactive mode is available, false otherwise.</returns>
47+
[Obsolete( "Use the less ambiguous InteractiveMode() enum value instead.", false)]
3148
[CakeAliasCategory( "Interactive mode" )]
3249
[CakeMethodAlias]
3350
public static bool IsInteractiveMode( this ICakeContext context )
@@ -36,11 +53,12 @@ public static bool IsInteractiveMode( this ICakeContext context )
3653
}
3754

3855
/// <summary>
39-
/// Gets whether the context supports interaction with the user (this can be true only if <see cref="IsInteractiveMode(ICakeContext)"/>
40-
/// is true) in automatic mode.
56+
/// Gets whether the context supports automatic interaction (argument -autointeraction has been provided).
57+
/// When this is true, <see cref="IsInteractiveMode"/> is false.
4158
/// </summary>
4259
/// <param name="context">The context.</param>
4360
/// <returns>True if interactive mode is available, false otherwise.</returns>
61+
[Obsolete( "Use the less ambiguous InteractiveMode() enum value instead.", false )]
4462
[CakeAliasCategory( "Interactive mode" )]
4563
[CakeMethodAlias]
4664
public static bool IsAutoInteractiveMode( this ICakeContext context )
@@ -90,7 +108,8 @@ public static char ReadInteractiveOption( this ICakeContext context, string argu
90108
static char DoReadInteractiveOption( ICakeContext context, string argumentName, string message, char[] options )
91109
{
92110
if( options == null || options.Length == 0 ) throw new ArgumentException( "At least one (uppercase) character for options must be provided." );
93-
if( !IsInteractiveMode( context ) ) throw new InvalidOperationException( "Interactions are not allowed." );
111+
var mode = InteractiveMode( context );
112+
if( mode == CodeCake.InteractiveMode.NoInteraction ) throw new InvalidOperationException( "Interactions are not allowed." );
94113
if( options.Any( c => char.IsLower( c ) ) ) throw new ArgumentException( "Options must be uppercase letter." );
95114

96115
string choices = String.Join( "/", options );
@@ -116,7 +135,7 @@ static char DoReadInteractiveOption( ICakeContext context, string argumentName,
116135
return c;
117136
}
118137
}
119-
if( IsAutoInteractiveMode( context ) )
138+
if( mode == CodeCake.InteractiveMode.AutoInteraction )
120139
{
121140
char c = options[0];
122141
Console.WriteLine( c );
@@ -152,10 +171,11 @@ static char DoReadInteractiveOption( ICakeContext context, string argumentName,
152171
public static string InteractiveEnvironmentVariable( this ICakeContext context, string variable, bool setCache = true )
153172
{
154173
string v = context.EnvironmentVariable( variable );
155-
if( v == null && IsInteractiveMode( context ) )
174+
var mode = InteractiveMode( context );
175+
if( v == null && mode != CodeCake.InteractiveMode.NoInteraction )
156176
{
157177
Console.Write( $"Environment Variable '{variable}' not found. Enter its value: " );
158-
if( IsAutoInteractiveMode( context ) )
178+
if( mode == CodeCake.InteractiveMode.AutoInteraction )
159179
{
160180
string fromArgName = "ENV:" + variable;
161181
string fromArg = context.Arguments.HasArgument( fromArgName ) ? context.Arguments.GetArgument( fromArgName ) : null;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace CodeCake
6+
{
7+
/// <summary>
8+
/// Defines the 3 interactive mode handled by <see cref="InteractiveAliases"/>.
9+
/// </summary>
10+
public enum InteractiveMode
11+
{
12+
/// <summary>
13+
/// No user interaction are supported (command line argument -nointeraction).
14+
/// </summary>
15+
NoInteraction,
16+
17+
/// <summary>
18+
/// Auto interaction (command line argument -autointeraction) is an hybrid mode where answers
19+
/// are read from the command line or, for <see cref="InteractiveAliases.ReadInteractiveOption(Cake.Core.ICakeContext, string, string, char[])"/>,
20+
/// the first choice is choosen.
21+
/// </summary>
22+
AutoInteraction,
23+
24+
/// <summary>
25+
/// User has to answer the questions.
26+
/// </summary>
27+
Interactive
28+
}
29+
}

Code.Cake/RunResult.cs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,19 @@ public struct RunResult
1717
public readonly int ReturnCode;
1818

1919
/// <summary>
20-
/// Gets whether the context is in interactive
21-
/// mode (see <see cref="InteractiveAliases.IsInteractiveMode(Cake.Core.ICakeContext)"/>).
20+
/// Gets the context's interactive mode.
2221
/// </summary>
23-
public readonly bool IsInteractiveMode;
24-
25-
/// <summary>
26-
/// Gets whether the context is in auto interactive
27-
/// mode (see <see cref="InteractiveAliases.IsAutoInteractiveMode(Cake.Core.ICakeContext)"/>).
28-
/// </summary>
29-
public readonly bool IsAutoInteractiveMode;
22+
public readonly InteractiveMode InteractiveMode;
3023

3124
/// <summary>
3225
/// Gets whether the run succeeded (<see cref="ReturnCode"/> is 0).
3326
/// </summary>
3427
public bool Success => ReturnCode == 0;
3528

36-
internal RunResult( int returnCode, bool isInteractiveMode, bool isAutoInteractiveMode )
37-
{ ReturnCode = returnCode;
38-
IsInteractiveMode = isInteractiveMode;
39-
IsAutoInteractiveMode = isAutoInteractiveMode;
29+
internal RunResult( int returnCode, InteractiveMode mode )
30+
{
31+
ReturnCode = returnCode;
32+
InteractiveMode = mode;
4033
}
4134

4235
/// <summary>

CodeCakeBuilder/Build.StandardCheckRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ string StandardCheckRepository( IEnumerable<SolutionProject> projectsToPublish,
1515
string configuration = "Debug";
1616
if( !gitInfo.IsValid )
1717
{
18-
if( Cake.IsInteractiveMode()
18+
if( Cake.InteractiveMode() != InteractiveMode.NoInteraction
1919
&& Cake.ReadInteractiveOption( "PublishDirtyRepo", "Repository is not ready to be published. Proceed anyway?", 'Y', 'N' ) == 'Y' )
2020
{
2121
Cake.Warning( "GitInfo is not valid, but you choose to continue..." );

CodeCakeBuilder/Build.StandardPushNuGetPackages.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public partial class Build
1515

1616
void StandardPushNuGetPackages( IEnumerable<FilePath> nugetPackages, SimpleRepositoryInfo gitInfo )
1717
{
18-
if( Cake.IsInteractiveMode() )
18+
if( Cake.InteractiveMode() != InteractiveMode.NoInteraction )
1919
{
2020
var localFeed = Cake.FindDirectoryAbove( "LocalFeed" );
2121
if( localFeed != null )

CodeCakeBuilder/Build.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ void ShouldFindTestTxtFileFromDynamicPaths( bool shouldFind )
132132
Task( "Push-NuGet-Packages" )
133133
.IsDependentOn( "Create-NuGet-Packages" )
134134
.WithCriteria( () => gitInfo.IsValid )
135-
.Does( () =>
135+
.Does( () =>
136136
{
137137
StandardPushNuGetPackages( Cake.GetFiles( releasesDir.Path + "/*.nupkg" ), gitInfo );
138138
} );

CodeCakeBuilder/Program.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,18 @@ class Program
1010
/// </summary>
1111
/// <param name="args">The command line arguments.</param>
1212
/// <returns>An error code (typically negative), 0 on success.</returns>
13-
static int Main(string[] args)
13+
static int Main( string[] args )
1414
{
1515
var app = new CodeCakeApplication();
16-
RunResult result = app.Run(args);
17-
if (result.IsInteractiveMode)
16+
RunResult result = app.Run( args );
17+
if( result.InteractiveMode == InteractiveMode.Interactive )
1818
{
1919
Console.WriteLine();
20-
Console.WriteLine($"Hit any key to exit.");
21-
Console.WriteLine($"Use -{InteractiveAliases.NoInteractionArgument} or -{InteractiveAliases.AutoInteractionArgument} parameter to exit immediately.");
20+
Console.WriteLine( $"Hit any key to exit." );
21+
Console.WriteLine( $"Use -{InteractiveAliases.NoInteractionArgument} or -{InteractiveAliases.AutoInteractionArgument} parameter to exit immediately." );
2222
Console.ReadKey();
2323
}
2424
return result.ReturnCode;
25-
2625
}
2726
}
2827
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"profiles": {
3+
"Run": {
4+
"commandName": "project",
5+
"commandLineArgs": "-autointeraction"
6+
}
7+
}
8+
}

0 commit comments

Comments
 (0)