Skip to content

Commit

Permalink
Merge pull request #3723 from fable-compiler/fix_logging_version
Browse files Browse the repository at this point in the history
Fix logging initialisation to allow `--version` to work
  • Loading branch information
MangelMaxime authored Jan 29, 2024
2 parents a3486b4 + dc2f8ef commit d8a832e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 46 deletions.
6 changes: 6 additions & 0 deletions src/Fable.Cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
94 changes: 48 additions & 46 deletions src/Fable.Cli/Entry.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

[<EntryPoint>]
let main argv =
result {
Expand Down Expand Up @@ -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 ()
Expand Down

0 comments on commit d8a832e

Please sign in to comment.