From 5ad191b9eb4aaa3a83257f88a2c10afba8604ebd Mon Sep 17 00:00:00 2001 From: Garrett Serack Date: Wed, 1 Jun 2016 14:21:29 -0700 Subject: [PATCH] Fixes #1019 - Verbose parameter and other costmetic issues (#1113) * Fixes #1019 - Verbose parameter and other costmetic issues * quick fix for verify-settings script * added documentation about JSON or YAML for input --- AutoRest/AutoRest.Core/AutoRest.cs | 2 ++ .../Extensibility/ExtensionsLoader.cs | 2 +- AutoRest/AutoRest.Core/Logging/Logger.cs | 11 ++++++++ .../Properties/Resources.Designer.cs | 11 +++++++- .../AutoRest.Core/Properties/Resources.resx | 5 +++- AutoRest/AutoRest.Core/Settings.cs | 6 +++++ AutoRest/AutoRest/Program.cs | 16 ++++++----- Documentation/cli.md | 27 ++++++++++--------- Tools/verify-settings.ps1 | 2 +- 9 files changed, 58 insertions(+), 24 deletions(-) diff --git a/AutoRest/AutoRest.Core/AutoRest.cs b/AutoRest/AutoRest.Core/AutoRest.cs index 2041e7ac81..d732ff6639 100644 --- a/AutoRest/AutoRest.Core/AutoRest.cs +++ b/AutoRest/AutoRest.Core/AutoRest.cs @@ -50,6 +50,8 @@ public static void Generate(Settings settings) throw ErrorManager.CreateError(exception, Resources.ErrorGeneratingClientModel, exception.Message); } CodeGenerator codeGenerator = ExtensionsLoader.GetCodeGenerator(settings); + Logger.WriteOutput(codeGenerator.UsageInstructions); + settings.Validate(); try { diff --git a/AutoRest/AutoRest.Core/Extensibility/ExtensionsLoader.cs b/AutoRest/AutoRest.Core/Extensibility/ExtensionsLoader.cs index 4aefb53b87..8f4cb29654 100644 --- a/AutoRest/AutoRest.Core/Extensibility/ExtensionsLoader.cs +++ b/AutoRest/AutoRest.Core/Extensibility/ExtensionsLoader.cs @@ -77,7 +77,7 @@ public static CodeGenerator GetCodeGenerator(Settings settings) /// Modeler specified in Settings.Modeler public static Modeler GetModeler(Settings settings) { - Logger.LogInfo(Resources.ModelerInitialized); + Logger.LogInfo(Resources.InitializingModeler); if (settings == null) { throw new ArgumentNullException("settings", "settings or settings.Modeler cannot be null."); diff --git a/AutoRest/AutoRest.Core/Logging/Logger.cs b/AutoRest/AutoRest.Core/Logging/Logger.cs index 846c274678..e003f217ce 100644 --- a/AutoRest/AutoRest.Core/Logging/Logger.cs +++ b/AutoRest/AutoRest.Core/Logging/Logger.cs @@ -37,6 +37,17 @@ public static void LogInfo(string message, params object[] args) Entries.Add(new LogEntry(LogEntrySeverity.Info, string.Format(CultureInfo.InvariantCulture, message, args))); } + /// + /// An abstraction for the core to output text (ie not err,warning, or info) + /// + /// + /// + public static void WriteOutput(string message, params object[] args) + { + Console.ResetColor(); + Console.WriteLine(message, args); + } + /// /// Logs a message of severity LogEntrySeverity.Warning. /// diff --git a/AutoRest/AutoRest.Core/Properties/Resources.Designer.cs b/AutoRest/AutoRest.Core/Properties/Resources.Designer.cs index c4fe1ce315..2ef7dbdc58 100644 --- a/AutoRest/AutoRest.Core/Properties/Resources.Designer.cs +++ b/AutoRest/AutoRest.Core/Properties/Resources.Designer.cs @@ -177,6 +177,15 @@ internal static string InitializingCodeGenerator { } } + /// + /// Looks up a localized string similar to Initializing modeler.. + /// + internal static string InitializingModeler { + get { + return ResourceManager.GetString("InitializingModeler", resourceCulture); + } + } + /// /// Looks up a localized string similar to Property name {0} cannot be used as an Identifier, as it contains only invalid characters.. /// @@ -196,7 +205,7 @@ internal static string LanguageDoesNotSupportSingleFileGeneration { } /// - /// Looks up a localized string similar to Initializing modeler.. + /// Looks up a localized string similar to Successfully initialized modeler {0} v {1}.. /// internal static string ModelerInitialized { get { diff --git a/AutoRest/AutoRest.Core/Properties/Resources.resx b/AutoRest/AutoRest.Core/Properties/Resources.resx index 50a7bfb31d..18688acae3 100644 --- a/AutoRest/AutoRest.Core/Properties/Resources.resx +++ b/AutoRest/AutoRest.Core/Properties/Resources.resx @@ -156,6 +156,9 @@ Initializing code generator. + + Initializing modeler. + Property name {0} cannot be used as an Identifier, as it contains only invalid characters. @@ -163,7 +166,7 @@ '{0}' code generator does not support code generation to a single file. - Initializing modeler. + Successfully initialized modeler {0} v {1}. {0} (already used in {1}) diff --git a/AutoRest/AutoRest.Core/Settings.cs b/AutoRest/AutoRest.Core/Settings.cs index 94c9fb7f52..63675cf0e4 100644 --- a/AutoRest/AutoRest.Core/Settings.cs +++ b/AutoRest/AutoRest.Core/Settings.cs @@ -195,6 +195,12 @@ public string Header [SettingsAlias("help")] public bool ShowHelp { get; set; } + /// + /// If set to true, print out all messages. + /// + [SettingsAlias("verbose")] + public bool Verbose { get; set; } + /// /// PackageName of then generated code package. Should be then names wanted for the package in then package manager. /// diff --git a/AutoRest/AutoRest/Program.cs b/AutoRest/AutoRest/Program.cs index f7bdf406b1..9871e76af2 100644 --- a/AutoRest/AutoRest/Program.cs +++ b/AutoRest/AutoRest/Program.cs @@ -33,8 +33,6 @@ private static int Main(string[] args) else { AutoRest.Generate(settings); - var codeGenerator = ExtensionsLoader.GetCodeGenerator(settings); - Console.WriteLine(codeGenerator.UsageInstructions); } } catch (CodeGenerationException) @@ -75,17 +73,21 @@ private static int Main(string[] args) } } - Logger.WriteErrors(Console.Error, - args.Any(a => "-Verbose".Equals(a, StringComparison.OrdinalIgnoreCase))); - - Logger.WriteWarnings(Console.Out); - + Console.ResetColor(); // Include LogEntrySeverity.Infos for verbose logging. if (args.Any(a => "-Verbose".Equals(a, StringComparison.OrdinalIgnoreCase))) { + Console.ForegroundColor = ConsoleColor.White; Logger.WriteInfos(Console.Out); } + Console.ForegroundColor = ConsoleColor.Yellow; + Logger.WriteWarnings(Console.Out); + + Console.ForegroundColor = ConsoleColor.Red; + Logger.WriteErrors(Console.Error, + args.Any(a => "-Verbose".Equals(a, StringComparison.OrdinalIgnoreCase))); + Console.ResetColor(); } } diff --git a/Documentation/cli.md b/Documentation/cli.md index 6ffe3f7790..4dddaeec8a 100644 --- a/Documentation/cli.md +++ b/Documentation/cli.md @@ -1,10 +1,10 @@ #AutoRest Command Line Interface Documentation ##Syntax -`AutoRest.exe -Input [-Namespace ] [-OutputDirectory ] [-CodeGenerator ] [-Modeler ] [-ClientName ] [-PayloadFlatteningThreshold ] [-Header ] [-AddCredentials ] [-OutputFileName ]` +`AutoRest.exe -Input [-Verbose] [-Namespace ] [-OutputDirectory ] [-CodeGenerator ] [-Modeler ] [-ClientName ] [-PayloadFlatteningThreshold ] [-Header ] [-AddCredentials ] [-OutputFileName ]` ##Parameters - **-Input** The location of the input specification. Aliases: -i, -input + **-Input** The location of the input specification. Aliases: -i, -input . The input file may be either in JSON or YAML format. **-Namespace** The namespace to use for generated code. Aliases: -n @@ -23,28 +23,29 @@ **-AddCredentials** If true, the generated client includes a ServiceClientCredentials property and constructor parameter. Authentication behaviors are implemented by extending the ServiceClientCredentials type. **-OutputFileName** If set, will cause generated code to be output to a single file. Not supported by all code generators. - + + **-Verbose** If set, will output verbose diagnostic messages. ##Code Generators - **-Ruby** Generic Ruby code generator. + **Ruby** Generic Ruby code generator. - **-Azure.Ruby** Azure specific Ruby code generator. + **Azure.Ruby** Azure specific Ruby code generator. - **-CSharp** Generic C# code generator. + **CSharp** Generic C# code generator. - **-Azure.CSharp** Azure specific C# code generator. + **Azure.CSharp** Azure specific C# code generator. - **-NodeJS** Generic NodeJS code generator. + **NodeJS** Generic NodeJS code generator. - **-Azure.NodeJS** Azure specific NodeJS code generator. + **Azure.NodeJS** Azure specific NodeJS code generator. - **-Java** Generic Java code generator. + **Java** Generic Java code generator. - **-Azure.Java** Azure specific Java code generator. + **Azure.Java** Azure specific Java code generator. - **-Python** Generic Python code generator. + **Python** Generic Python code generator. - **-Azure.Python** Azure specific Python code generator. + **Azure.Python** Azure specific Python code generator. ##Code Generator Specific Settings ###CSharp diff --git a/Tools/verify-settings.ps1 b/Tools/verify-settings.ps1 index bb419ddeba..b8f0ee93cc 100644 --- a/Tools/verify-settings.ps1 +++ b/Tools/verify-settings.ps1 @@ -114,7 +114,7 @@ function which( if( $env:path ) { foreach( $dir in $env:path.Split(";")) { foreach( $ext in (";.ps1;"+$env:pathext).split(";")) { - if( $dir -and (resolve-path $dir) ) { + if( $dir -and (resolve-path $dir -ea 0 ) ) { $p = join-path $dir "$cmd$ext" if( exists $p ) { if( Validate -exe $p $arch $include $exclude $minimumVersion ) {