Merge pull request #3579 from Priya91/rel/1.0.0-preview2

Remove showing firsttime eula for non verbs.
This commit is contained in:
Josh Free 2016-06-15 17:02:34 -07:00 committed by GitHub
commit ef9ad4044a
3 changed files with 82 additions and 53 deletions

View file

@ -55,11 +55,9 @@ namespace Microsoft.DotNet.Cli
try try
{ {
ConfigureDotNetForFirstTimeUse();
using (PerfTrace.Current.CaptureTiming()) using (PerfTrace.Current.CaptureTiming())
{ {
return ProcessArgs(args, new Telemetry()); return ProcessArgs(args);
} }
} }
catch (GracefulException e) catch (GracefulException e)
@ -78,7 +76,7 @@ namespace Microsoft.DotNet.Cli
} }
} }
internal static int ProcessArgs(string[] args, ITelemetry telemetryClient) internal static int ProcessArgs(string[] args, ITelemetry telemetryClient = null)
{ {
// CommandLineApplication is a bit restrictive, so we parse things ourselves here. Individual apps should use CLA. // CommandLineApplication is a bit restrictive, so we parse things ourselves here. Individual apps should use CLA.
@ -86,43 +84,53 @@ namespace Microsoft.DotNet.Cli
var success = true; var success = true;
var command = string.Empty; var command = string.Empty;
var lastArg = 0; var lastArg = 0;
for (; lastArg < args.Length; lastArg++) using (INuGetCacheSentinel nugetCacheSentinel = new NuGetCacheSentinel())
{ {
if (IsArg(args[lastArg], "v", "verbose")) for (; lastArg < args.Length; lastArg++)
{ {
verbose = true; if (IsArg(args[lastArg], "v", "verbose"))
{
verbose = true;
}
else if (IsArg(args[lastArg], "version"))
{
PrintVersion();
return 0;
}
else if (IsArg(args[lastArg], "info"))
{
PrintInfo();
return 0;
}
else if (IsArg(args[lastArg], "h", "help"))
{
HelpCommand.PrintHelp();
return 0;
}
else if (args[lastArg].StartsWith("-"))
{
Reporter.Error.WriteLine($"Unknown option: {args[lastArg]}");
success = false;
}
else
{
ConfigureDotNetForFirstTimeUse(nugetCacheSentinel);
// It's the command, and we're done!
command = args[lastArg];
break;
}
} }
else if (IsArg(args[lastArg], "version")) if (!success)
{
PrintVersion();
return 0;
}
else if (IsArg(args[lastArg], "info"))
{
PrintInfo();
return 0;
}
else if (IsArg(args[lastArg], "h", "help"))
{ {
HelpCommand.PrintHelp(); HelpCommand.PrintHelp();
return 0; return 1;
} }
else if (args[lastArg].StartsWith("-"))
if (telemetryClient == null)
{ {
Reporter.Error.WriteLine($"Unknown option: {args[lastArg]}"); telemetryClient = new Telemetry(nugetCacheSentinel);
success = false;
} }
else
{
// It's the command, and we're done!
command = args[lastArg];
break;
}
}
if (!success)
{
HelpCommand.PrintHelp();
return 1;
} }
var appArgs = (lastArg + 1) >= args.Length ? Enumerable.Empty<string>() : args.Skip(lastArg + 1).ToArray(); var appArgs = (lastArg + 1) >= args.Length ? Enumerable.Empty<string>() : args.Skip(lastArg + 1).ToArray();
@ -160,25 +168,22 @@ namespace Microsoft.DotNet.Cli
} }
private static void ConfigureDotNetForFirstTimeUse() private static void ConfigureDotNetForFirstTimeUse(INuGetCacheSentinel nugetCacheSentinel)
{ {
using (PerfTrace.Current.CaptureTiming()) using (PerfTrace.Current.CaptureTiming())
{ {
using (var nugetPackagesArchiver = new NuGetPackagesArchiver()) using (var nugetPackagesArchiver = new NuGetPackagesArchiver())
{ {
using (var nugetCacheSentinel = new NuGetCacheSentinel()) var environmentProvider = new EnvironmentProvider();
{ var commandFactory = new DotNetCommandFactory();
var environmentProvider = new EnvironmentProvider(); var nugetCachePrimer =
var commandFactory = new DotNetCommandFactory(); new NuGetCachePrimer(commandFactory, nugetPackagesArchiver, nugetCacheSentinel);
var nugetCachePrimer = var dotnetConfigurer = new DotnetFirstTimeUseConfigurer(
new NuGetCachePrimer(commandFactory, nugetPackagesArchiver, nugetCacheSentinel); nugetCachePrimer,
var dotnetConfigurer = new DotnetFirstTimeUseConfigurer( nugetCacheSentinel,
nugetCachePrimer, environmentProvider);
nugetCacheSentinel,
environmentProvider);
dotnetConfigurer.Configure(); dotnetConfigurer.Configure();
}
} }
} }
} }

View file

@ -4,9 +4,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.ApplicationInsights; using Microsoft.ApplicationInsights;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Configurer;
using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.InternalAbstractions;
namespace Microsoft.DotNet.Cli namespace Microsoft.DotNet.Cli
@ -30,9 +32,11 @@ namespace Microsoft.DotNet.Cli
public bool Enabled { get; } public bool Enabled { get; }
public Telemetry() public Telemetry () : this(null) { }
public Telemetry(INuGetCacheSentinel sentinel)
{ {
Enabled = !Env.GetEnvironmentVariableAsBool(TelemetryOptout); Enabled = !Env.GetEnvironmentVariableAsBool(TelemetryOptout) && PermissionExists(sentinel);
if (!Enabled) if (!Enabled)
{ {
@ -43,6 +47,16 @@ namespace Microsoft.DotNet.Cli
_trackEventTask = Task.Factory.StartNew(() => InitializeTelemetry()); _trackEventTask = Task.Factory.StartNew(() => InitializeTelemetry());
} }
private bool PermissionExists(INuGetCacheSentinel sentinel)
{
if (sentinel == null)
{
return false;
}
return sentinel.Exists();
}
public void TrackEvent(string eventName, IDictionary<string, string> properties, IDictionary<string, double> measurements) public void TrackEvent(string eventName, IDictionary<string, string> properties, IDictionary<string, double> measurements)
{ {
if (!Enabled) if (!Enabled)

View file

@ -15,7 +15,8 @@ namespace Microsoft.DotNet.Tests
{ {
public class GivenThatTheUserIsRunningDotNetForTheFirstTime : TestBase public class GivenThatTheUserIsRunningDotNetForTheFirstTime : TestBase
{ {
private static CommandResult _firstDotnetUseCommandResult; private static CommandResult _firstDotnetNonVerbUseCommandResult;
private static CommandResult _firstDotnetVerbUseCommandResult;
private static DirectoryInfo _nugetCacheFolder; private static DirectoryInfo _nugetCacheFolder;
static GivenThatTheUserIsRunningDotNetForTheFirstTime() static GivenThatTheUserIsRunningDotNetForTheFirstTime()
@ -28,7 +29,8 @@ namespace Microsoft.DotNet.Tests
command.Environment["NUGET_PACKAGES"] = testNugetCache; command.Environment["NUGET_PACKAGES"] = testNugetCache;
command.Environment["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = ""; command.Environment["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = "";
_firstDotnetUseCommandResult = command.ExecuteWithCapturedOutput("new"); _firstDotnetNonVerbUseCommandResult = command.ExecuteWithCapturedOutput("--info");
_firstDotnetVerbUseCommandResult = command.ExecuteWithCapturedOutput("new");
_nugetCacheFolder = new DirectoryInfo(testNugetCache); _nugetCacheFolder = new DirectoryInfo(testNugetCache);
} }
@ -36,7 +38,15 @@ namespace Microsoft.DotNet.Tests
[Fact] [Fact]
public void Using_dotnet_for_the_first_time_succeeds() public void Using_dotnet_for_the_first_time_succeeds()
{ {
_firstDotnetUseCommandResult.Should().Pass(); _firstDotnetVerbUseCommandResult.Should().Pass();
}
[Fact]
public void Using_dotnet_for_the_first_time_with_non_verbs_doesnt_print_eula()
{
const string firstTimeNonVerbUseMessage = @".NET Command Line Tools";
_firstDotnetNonVerbUseCommandResult.StdOut.Should().StartWith(firstTimeNonVerbUseMessage);
} }
[Fact] [Fact]
@ -54,12 +64,12 @@ Configuring...
------------------- -------------------
A command is running to initially populate your local package cache, to improve restore speed and enable offline access. This command will take up to a minute to complete and will only happen once."; A command is running to initially populate your local package cache, to improve restore speed and enable offline access. This command will take up to a minute to complete and will only happen once.";
_firstDotnetUseCommandResult.StdOut.Should().StartWith(firstTimeUseWelcomeMessage); _firstDotnetVerbUseCommandResult.StdOut.Should().StartWith(firstTimeUseWelcomeMessage);
} }
[Fact] [Fact]
public void It_restores_the_nuget_packages_to_the_nuget_cache_folder() public void It_restores_the_nuget_packages_to_the_nuget_cache_folder()
{ {
_nugetCacheFolder.Should().HaveFile($"{GetDotnetVersion()}.dotnetSentinel"); _nugetCacheFolder.Should().HaveFile($"{GetDotnetVersion()}.dotnetSentinel");
} }