Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logging initialisation to allow --version to work #3723

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading