From dc2f8efc812532f178a052087c85036bd273c63b Mon Sep 17 00:00:00 2001 From: Maxime Mangel Date: Mon, 29 Jan 2024 22:02:29 +0100 Subject: [PATCH] Fix logging initialisation to allow `--version` to work --- src/Fable.Cli/CHANGELOG.md | 6 +++ src/Fable.Cli/Entry.fs | 94 +++++++++++++++++++------------------- 2 files changed, 54 insertions(+), 46 deletions(-) diff --git a/src/Fable.Cli/CHANGELOG.md b/src/Fable.Cli/CHANGELOG.md index 153565226f..db2ea7bb56 100644 --- a/src/Fable.Cli/CHANGELOG.md +++ b/src/Fable.Cli/CHANGELOG.md @@ -14,6 +14,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [GH-3719](https://github.com/fable-compiler/Fable/issues/3719) Restore dependencies against the `.fsproj` after evaluating the `fable-temp.csproj` file (Improves IDE supports) (by @MangelMaxime) * Don't delete `fable_modules` when re-evaluating the project file after a changes has been detected (Improves HMR experience) (by @MangelMaxime) +### Fixed + +#### All + +* [GH-3723](https://github.com/fable-compiler/Fable/pull/3723) Fix logging initialisation to allow `--version` to work (by @MangelMaxime) + #### JavaScript * [GH-3716](https://github.com/fable-compiler/Fable/pull/3716) System.Array.Resize: also handle the case where the array is null (by @chkn) diff --git a/src/Fable.Cli/Entry.fs b/src/Fable.Cli/Entry.fs index c5620b4452..05a5430ea7 100644 --- a/src/Fable.Cli/Entry.fs +++ b/src/Fable.Cli/Entry.fs @@ -560,6 +560,35 @@ let getLibPkgVersion = | Dart | Php -> None +let private logPrelude commands language = + match commands with + | [ "--version" ] -> () + | _ -> + let status = + match getStatus language with + | "stable" + | "" -> "" + | status -> $" (status: {status})" + + Log.always ( + $"Fable {Literals.VERSION}: F# to {language} compiler{status}" + ) + + match getLibPkgVersion language with + | Some(repository, pkgName, version) -> + Log.always ( + $"Minimum {pkgName} version (when installed from {repository}): {version}" + ) + | None -> () + + Log.always ( + "\nThanks to the contributor! @" + Contributors.getRandom () + ) + + Log.always ( + "Stand with Ukraine! https://standwithukraine.com.ua/" + "\n" + ) + [] let main argv = result { @@ -600,57 +629,30 @@ let main argv = | Some rootDir -> File.getExactFullPath rootDir | None -> IO.Directory.GetCurrentDirectory() - let verbosity = + let level, verbosity = match commands with - | [ "--version" ] -> Verbosity.Normal + | [ "--version" ] -> LogLevel.Information, Verbosity.Normal | _ -> - let verbosity = - let level, verbosity = - if args.FlagEnabled "--verbose" then - LogLevel.Debug, Fable.Verbosity.Verbose - else - LogLevel.Information, Fable.Verbosity.Normal - - use factory = - LoggerFactory.Create(fun builder -> - builder - .SetMinimumLevel(level) - .AddCustomConsole(fun options -> - options.UseNoPrefixMsgStyle <- true - ) - |> ignore - ) - - Log.setLogger (factory.CreateLogger("")) - verbosity - - let status = - match getStatus language with - | "stable" - | "" -> "" - | status -> $" (status: {status})" - - Log.always ( - $"Fable {Literals.VERSION}: F# to {language} compiler{status}" - ) - - match getLibPkgVersion language with - | Some(repository, pkgName, version) -> - Log.always ( - $"Minimum {pkgName} version (when installed from {repository}): {version}" + if args.FlagEnabled "--verbose" then + LogLevel.Debug, Verbosity.Verbose + else + LogLevel.Information, Verbosity.Normal + + // Initialize logging + let factory = + LoggerFactory.Create(fun builder -> + builder + .SetMinimumLevel(level) + .AddCustomConsole(fun options -> + options.UseNoPrefixMsgStyle <- true ) - | None -> () - - Log.always ( - "\nThanks to the contributor! @" + Contributors.getRandom () - ) + |> ignore + ) - Log.always ( - "Stand with Ukraine! https://standwithukraine.com.ua/" - + "\n" - ) + Log.setLogger (factory.CreateLogger("")) + factory.Dispose() - verbosity + logPrelude commands language match commands with | [ "--help" ] -> return printHelp ()