diff --git a/src/Paket.Core/Logging.fs b/src/Paket.Core/Logging.fs index a6d689c3ba..9d3b7811b2 100644 --- a/src/Paket.Core/Logging.fs +++ b/src/Paket.Core/Logging.fs @@ -2,82 +2,100 @@ open System open System.IO +open System.Diagnostics +/// [omit] let mutable verbose = false -let mutable logFile : string option = None -let traceFunctions = System.Collections.Generic.List<_>() +/// [omit] +type Trace = { + Level: TraceLevel + Text: string + NewLine: bool } -let setLogFile fileName = - let fi = FileInfo fileName - logFile <- Some fi.FullName - if fi.Exists then - fi.Delete() - else - if fi.Directory.Exists |> not then - fi.Directory.Create() +/// [omit] +let event = Event() -let inline traceToFile (text:string) = - match logFile with - | Some fileName -> try File.AppendAllLines(fileName,[text]) with | _ -> () - | _ -> () -let RegisterTraceFunction(traceFunction:Action) = - traceFunctions.Add(traceFunction) +/// [omit] +let tracen s = event.Trigger { Level = TraceLevel.Info; Text = s; NewLine = true } -let RemoveTraceFunction(traceFunction:Action) = - traceFunctions.Remove(traceFunction) +/// [omit] +let tracefn fmt = Printf.ksprintf tracen fmt -let inline traceToRegisteredFunctions (text:string) = - traceToFile text - for f in traceFunctions do - f.Invoke(text) +/// [omit] +let trace s = event.Trigger { Level = TraceLevel.Info; Text = s; NewLine = false } /// [omit] -let monitor = new Object() +let tracef fmt = Printf.ksprintf trace fmt /// [omit] -let inline tracen (s : string) = lock monitor (fun () -> traceToRegisteredFunctions s; Console.WriteLine s) +let traceVerbose s = + if verbose then + event.Trigger { Level = TraceLevel.Verbose; Text = s; NewLine = true } /// [omit] -let inline tracefn fmt = Printf.ksprintf tracen fmt +let verbosefn fmt = Printf.ksprintf traceVerbose fmt /// [omit] -let inline trace (s : string) = lock monitor (fun () -> traceToRegisteredFunctions s; Console.Write s) +let traceError s = event.Trigger { Level = TraceLevel.Error; Text = s; NewLine = true } /// [omit] -let inline tracef fmt = Printf.ksprintf trace fmt +let traceWarn s = event.Trigger { Level = TraceLevel.Warning; Text = s; NewLine = true } /// [omit] -let inline traceVerbose (s : string) = - if verbose then - lock monitor (fun () -> traceToRegisteredFunctions s; Console.WriteLine s) +let traceErrorfn fmt = Printf.ksprintf traceError fmt /// [omit] -let inline verbosefn fmt = Printf.ksprintf traceVerbose fmt +let traceWarnfn fmt = Printf.ksprintf traceWarn fmt + + +// Console Trace /// [omit] -let inline traceColored color (s: string) = - lock monitor - (fun () -> - let curColor = Console.ForegroundColor - if curColor <> color then Console.ForegroundColor <- color - traceToRegisteredFunctions s - use textWriter = - match color with - | ConsoleColor.Red -> Console.Error - | _ -> Console.Out - textWriter.WriteLine s - if curColor <> color then Console.ForegroundColor <- curColor) +let traceColored color (s:string) = + let curColor = Console.ForegroundColor + if curColor <> color then Console.ForegroundColor <- color + use textWriter = + match color with + | ConsoleColor.Red -> Console.Error + | _ -> Console.Out + textWriter.WriteLine s + if curColor <> color then Console.ForegroundColor <- curColor + +/// [omit] +let monitor = new Object() /// [omit] -let inline traceError s = traceColored ConsoleColor.Red s +let traceToConsole (trace:Trace) = + lock monitor + (fun () -> + match trace.Level with + | TraceLevel.Warning -> traceColored ConsoleColor.Yellow trace.Text + | TraceLevel.Error -> traceColored ConsoleColor.Red trace.Text + | _ -> + if trace.NewLine then Console.WriteLine trace.Text + else Console.Write trace.Text ) + + +// Log File Trace /// [omit] -let inline traceWarn s = traceColored ConsoleColor.Yellow s +let mutable logFile : string option = None /// [omit] -let inline traceErrorfn fmt = Printf.ksprintf traceError fmt +let traceToFile (trace:Trace) = + match logFile with + | Some fileName -> try File.AppendAllLines(fileName,[trace.Text]) with | _ -> () + | _ -> () /// [omit] -let inline traceWarnfn fmt = Printf.ksprintf traceWarn fmt \ No newline at end of file +let setLogFile fileName = + let fi = FileInfo fileName + logFile <- Some fi.FullName + if fi.Exists then + fi.Delete() + else + if fi.Directory.Exists |> not then + fi.Directory.Create() + event.Publish |> Observable.subscribe traceToFile \ No newline at end of file diff --git a/src/Paket.Core/Logging.fsi b/src/Paket.Core/Logging.fsi new file mode 100644 index 0000000000..bd7ee9cae2 --- /dev/null +++ b/src/Paket.Core/Logging.fsi @@ -0,0 +1,39 @@ +module Paket.Logging + +open System +open System.Diagnostics + +val mutable verbose : bool + + +val tracen : string -> unit + +val tracefn : Printf.StringFormat<'a,unit> -> 'a + +val trace : string -> unit + +val tracef : Printf.StringFormat<'a,unit> -> 'a + +val traceVerbose : string -> unit + +val verbosefn : Printf.StringFormat<'a,unit> -> 'a + +val traceError : string -> unit + +val traceWarn : string -> unit + +val traceErrorfn : Printf.StringFormat<'a,unit> -> 'a + +val traceWarnfn : Printf.StringFormat<'a,unit> -> 'a + + +type Trace = { + Level: TraceLevel + Text: string + NewLine: bool } + +val event : Event + +val traceToConsole : Trace -> unit + +val setLogFile : string -> IDisposable \ No newline at end of file diff --git a/src/Paket.Core/Paket.Core.fsproj b/src/Paket.Core/Paket.Core.fsproj index d9428cc066..8c5d1ff231 100644 --- a/src/Paket.Core/Paket.Core.fsproj +++ b/src/Paket.Core/Paket.Core.fsproj @@ -79,6 +79,7 @@ + @@ -267,4 +268,4 @@ - + \ No newline at end of file diff --git a/src/Paket.PowerShell/CmdletExt.fs b/src/Paket.PowerShell/CmdletExt.fs index 5c55ae5044..6c3cbdb265 100644 --- a/src/Paket.PowerShell/CmdletExt.fs +++ b/src/Paket.PowerShell/CmdletExt.fs @@ -2,6 +2,7 @@ module Paket.PowerShell.CmdletExt open System.Management.Automation +open Paket // add F# printf write extensions type Cmdlet with @@ -34,7 +35,4 @@ type PSCmdlet with let bps = x.MyInvocation.BoundParameters if bps.ContainsKey "Debug" then (bps.["Debug"] :?> SwitchParameter).ToBool() - else false - - member x.SetCurrentDirectoryToLocation() = - System.Environment.CurrentDirectory <- x.SessionState.Path.CurrentFileSystemLocation.Path \ No newline at end of file + else false \ No newline at end of file diff --git a/src/Paket.PowerShell/EventSink.fs b/src/Paket.PowerShell/EventSink.fs new file mode 100644 index 0000000000..0af4eb0baf --- /dev/null +++ b/src/Paket.PowerShell/EventSink.fs @@ -0,0 +1,31 @@ +namespace Paket.PowerShell + +open System +open System.Collections.Generic +open System.Collections.Concurrent + +type EventSink<'T>() = + let queue = new BlockingCollection<_>() + let subscriptions = List() + + member __.Fill callback (source:IObservable<'T>) = + source |> Observable.subscribe (fun state -> queue.Add((callback, state))) + |> subscriptions.Add + + member __.Drain() = + for callback, state in queue.GetConsumingEnumerable() do + callback state + + member __.StopFill() = + for sb in subscriptions do + use d = sb + () + queue.CompleteAdding() + + interface IDisposable with + member x.Dispose() = + for s in subscriptions do + use d = s + () + use d = queue + () \ No newline at end of file diff --git a/src/Paket.PowerShell/Paket.PowerShell.fsproj b/src/Paket.PowerShell/Paket.PowerShell.fsproj index d81626cc56..98573321bb 100644 --- a/src/Paket.PowerShell/Paket.PowerShell.fsproj +++ b/src/Paket.PowerShell/Paket.PowerShell.fsproj @@ -23,6 +23,11 @@ 3 + Project + + + + pdbonly @@ -38,6 +43,7 @@ + diff --git a/src/Paket.PowerShell/PowerShell.fs b/src/Paket.PowerShell/PowerShell.fs index 1577231c1b..ea28084fef 100644 --- a/src/Paket.PowerShell/PowerShell.fs +++ b/src/Paket.PowerShell/PowerShell.fs @@ -1,11 +1,37 @@ namespace Paket.PowerShell open System.Management.Automation +open System.Diagnostics open Paket open Paket.Commands open Nessos.UnionArgParser open System +[] +module PaketPs = + + let processWithLogging (cmdlet:PSCmdlet) computation = + Environment.CurrentDirectory <- cmdlet.SessionState.Path.CurrentFileSystemLocation.Path + Logging.verbose <- cmdlet.Verbose + use sink = new EventSink() + + Logging.event.Publish |> sink.Fill (fun trace -> + match trace.Level with + | TraceLevel.Error -> cmdlet.WriteWarning trace.Text + | TraceLevel.Warning -> cmdlet.WriteWarning trace.Text + | TraceLevel.Verbose -> cmdlet.WriteVerbose trace.Text + | _ -> cmdlet.WriteObject trace.Text ) + + async { + try + do! Async.SwitchToNewThread() + do! computation + finally + sink.StopFill() + } |> Async.Start + + sink.Drain() + [] type Add() = inherit PSCmdlet() @@ -19,28 +45,28 @@ type Add() = [] member val NoInstall = SwitchParameter() with get, set override x.ProcessRecord() = - Logging.verbose <- x.Verbose - x.SetCurrentDirectoryToLocation() - let parser = UnionArgParser.Create() - seq { - if String.IsNullOrEmpty x.NuGet = false then - yield AddArgs.Nuget x.NuGet - if String.IsNullOrEmpty x.Version = false then - yield AddArgs.Version x.Version - if String.IsNullOrEmpty x.Project = false then - yield AddArgs.Project x.Project - if x.Force.IsPresent then - yield AddArgs.Force - if x.Interactive.IsPresent then - yield AddArgs.Interactive - if x.Hard.IsPresent then - yield AddArgs.Hard - if x.NoInstall.IsPresent then - yield AddArgs.No_Install - } - |> List.ofSeq - |> parser.CreateParseResultsOfList - |> Program.add + async { + let parser = UnionArgParser.Create() + seq { + if String.IsNullOrEmpty x.NuGet = false then + yield AddArgs.Nuget x.NuGet + if String.IsNullOrEmpty x.Version = false then + yield AddArgs.Version x.Version + if String.IsNullOrEmpty x.Project = false then + yield AddArgs.Project x.Project + if x.Force.IsPresent then + yield AddArgs.Force + if x.Interactive.IsPresent then + yield AddArgs.Interactive + if x.Hard.IsPresent then + yield AddArgs.Hard + if x.NoInstall.IsPresent then + yield AddArgs.No_Install + } + |> List.ofSeq + |> parser.CreateParseResultsOfList + |> Program.add + } |> processWithLogging x [] type AutoRestoreCmdlet() = @@ -50,18 +76,18 @@ type AutoRestoreCmdlet() = [] member val Off = SwitchParameter() with get, set override x.ProcessRecord() = - Logging.verbose <- x.Verbose - x.SetCurrentDirectoryToLocation() - let parser = UnionArgParser.Create() - seq { - if x.On.IsPresent then - yield AutoRestoreArgs.On - if x.Off.IsPresent then - yield AutoRestoreArgs.Off - } - |> List.ofSeq - |> parser.CreateParseResultsOfList - |> Program.autoRestore + async { + let parser = UnionArgParser.Create() + seq { + if x.On.IsPresent then + yield AutoRestoreArgs.On + if x.Off.IsPresent then + yield AutoRestoreArgs.Off + } + |> List.ofSeq + |> parser.CreateParseResultsOfList + |> Program.autoRestore + } |> processWithLogging x [] type ConfigCmdlet() = @@ -70,16 +96,16 @@ type ConfigCmdlet() = [] member val AddCredentials = "" with get, set override x.ProcessRecord() = - Logging.verbose <- x.Verbose - x.SetCurrentDirectoryToLocation() - let parser = UnionArgParser.Create() - seq { - if String.IsNullOrEmpty x.AddCredentials = false then - yield ConfigArgs.AddCredentials x.AddCredentials - } - |> List.ofSeq - |> parser.CreateParseResultsOfList - |> Program.config + async { + let parser = UnionArgParser.Create() + seq { + if String.IsNullOrEmpty x.AddCredentials = false then + yield ConfigArgs.AddCredentials x.AddCredentials + } + |> List.ofSeq + |> parser.CreateParseResultsOfList + |> Program.config + } |> processWithLogging x [] type ConvertFromNuGetCmdlet() = @@ -92,22 +118,22 @@ type ConvertFromNuGetCmdlet() = [] member val CredsMigration = "encrypt" with get, set override x.ProcessRecord() = - Logging.verbose <- x.Verbose - x.SetCurrentDirectoryToLocation() - let parser = UnionArgParser.Create() - seq { - if x.Force.IsPresent then - yield ConvertFromNugetArgs.Force - if x.NoInstall.IsPresent then - yield ConvertFromNugetArgs.No_Install - if x.NoAutoRestore.IsPresent then - yield ConvertFromNugetArgs.No_Auto_Restore - if String.IsNullOrEmpty x.CredsMigration = false then - yield ConvertFromNugetArgs.Creds_Migration x.CredsMigration - } - |> List.ofSeq - |> parser.CreateParseResultsOfList - |> Program.convert + async { + let parser = UnionArgParser.Create() + seq { + if x.Force.IsPresent then + yield ConvertFromNugetArgs.Force + if x.NoInstall.IsPresent then + yield ConvertFromNugetArgs.No_Install + if x.NoAutoRestore.IsPresent then + yield ConvertFromNugetArgs.No_Auto_Restore + if String.IsNullOrEmpty x.CredsMigration = false then + yield ConvertFromNugetArgs.Creds_Migration x.CredsMigration + } + |> List.ofSeq + |> parser.CreateParseResultsOfList + |> Program.convert + } |> processWithLogging x [] type FindRefsCmdlet() = @@ -116,16 +142,16 @@ type FindRefsCmdlet() = [] member val NuGet : string[] = Array.empty with get, set override x.ProcessRecord() = - Logging.verbose <- x.Verbose - x.SetCurrentDirectoryToLocation() - let parser = UnionArgParser.Create() - seq { - for p in x.NuGet do - yield FindRefsArgs.Packages p - } - |> List.ofSeq - |> parser.CreateParseResultsOfList - |> Program.findRefs + async { + let parser = UnionArgParser.Create() + seq { + for p in x.NuGet do + yield FindRefsArgs.Packages p + } + |> List.ofSeq + |> parser.CreateParseResultsOfList + |> Program.findRefs + } |> processWithLogging x [] type FindPackagesCmdlet() = @@ -137,22 +163,22 @@ type FindPackagesCmdlet() = [] member val Silent = SwitchParameter() with get, set override x.ProcessRecord() = - Logging.verbose <- x.Verbose - x.SetCurrentDirectoryToLocation() - let parser = UnionArgParser.Create() - seq { - if String.IsNullOrEmpty x.SearchText = false then - yield FindPackagesArgs.SearchText x.SearchText - if String.IsNullOrEmpty x.Source = false then - yield FindPackagesArgs.Source x.Source - if x.Max <> Int32.MinValue then - yield FindPackagesArgs.MaxResults x.Max - if x.Silent.IsPresent then - yield FindPackagesArgs.Silent - } - |> List.ofSeq - |> parser.CreateParseResultsOfList - |> Program.findPackages + async { + let parser = UnionArgParser.Create() + seq { + if String.IsNullOrEmpty x.SearchText = false then + yield FindPackagesArgs.SearchText x.SearchText + if String.IsNullOrEmpty x.Source = false then + yield FindPackagesArgs.Source x.Source + if x.Max <> Int32.MinValue then + yield FindPackagesArgs.MaxResults x.Max + if x.Silent.IsPresent then + yield FindPackagesArgs.Silent + } + |> List.ofSeq + |> parser.CreateParseResultsOfList + |> Program.findPackages + } |> processWithLogging x [] type FindPackageVersionsCmdlet() = @@ -164,34 +190,34 @@ type FindPackageVersionsCmdlet() = [] member val Silent = SwitchParameter() with get, set override x.ProcessRecord() = - Logging.verbose <- x.Verbose - x.SetCurrentDirectoryToLocation() - let parser = UnionArgParser.Create() - seq { - if String.IsNullOrEmpty x.Name = false then - yield FindPackageVersionsArgs.Name x.Name - if String.IsNullOrEmpty x.Source = false then - yield FindPackageVersionsArgs.Source x.Source - if x.Max <> Int32.MinValue then - yield FindPackageVersionsArgs.MaxResults x.Max - if x.Silent.IsPresent then - yield FindPackageVersionsArgs.Silent - } - |> List.ofSeq - |> parser.CreateParseResultsOfList - |> Program.findPackageVersions + async { + let parser = UnionArgParser.Create() + seq { + if String.IsNullOrEmpty x.Name = false then + yield FindPackageVersionsArgs.Name x.Name + if String.IsNullOrEmpty x.Source = false then + yield FindPackageVersionsArgs.Source x.Source + if x.Max <> Int32.MinValue then + yield FindPackageVersionsArgs.MaxResults x.Max + if x.Silent.IsPresent then + yield FindPackageVersionsArgs.Silent + } + |> List.ofSeq + |> parser.CreateParseResultsOfList + |> Program.findPackageVersions + } |> processWithLogging x [] type InitCmdlet() = inherit PSCmdlet() override x.ProcessRecord() = - Logging.verbose <- x.Verbose - x.SetCurrentDirectoryToLocation() - let parser = UnionArgParser.Create() - List.empty - |> parser.CreateParseResultsOfList - |> Program.init + async { + let parser = UnionArgParser.Create() + List.empty + |> parser.CreateParseResultsOfList + |> Program.init + } |> processWithLogging x [] type InstallCmdlet() = @@ -202,20 +228,20 @@ type InstallCmdlet() = [] member val Redirects = SwitchParameter() with get, set override x.ProcessRecord() = - Logging.verbose <- x.Verbose - x.SetCurrentDirectoryToLocation() - let parser = UnionArgParser.Create() - seq { - if x.Force.IsPresent then - yield InstallArgs.Force - if x.Hard.IsPresent then - yield InstallArgs.Hard - if x.Redirects.IsPresent then - yield InstallArgs.Redirects - } - |> List.ofSeq - |> parser.CreateParseResultsOfList - |> Program.install + async { + let parser = UnionArgParser.Create() + seq { + if x.Force.IsPresent then + yield InstallArgs.Force + if x.Hard.IsPresent then + yield InstallArgs.Hard + if x.Redirects.IsPresent then + yield InstallArgs.Redirects + } + |> List.ofSeq + |> parser.CreateParseResultsOfList + |> Program.install + } |> processWithLogging x [] type OutdatedCmdlet() = @@ -225,18 +251,18 @@ type OutdatedCmdlet() = [] member val IncludePrereleases = SwitchParameter() with get, set override x.ProcessRecord() = - Logging.verbose <- x.Verbose - x.SetCurrentDirectoryToLocation() - let parser = UnionArgParser.Create() - seq { - if x.IgnoreConstraints.IsPresent then - yield OutdatedArgs.Ignore_Constraints - if x.IncludePrereleases.IsPresent then - yield OutdatedArgs.Include_Prereleases - } - |> List.ofSeq - |> parser.CreateParseResultsOfList - |> Program.outdated + async { + let parser = UnionArgParser.Create() + seq { + if x.IgnoreConstraints.IsPresent then + yield OutdatedArgs.Ignore_Constraints + if x.IncludePrereleases.IsPresent then + yield OutdatedArgs.Include_Prereleases + } + |> List.ofSeq + |> parser.CreateParseResultsOfList + |> Program.outdated + } |> processWithLogging x [] type PushCmdlet() = @@ -248,22 +274,22 @@ type PushCmdlet() = [] member val Endpoint = "" with get, set override x.ProcessRecord() = - Logging.verbose <- x.Verbose - x.SetCurrentDirectoryToLocation() - let parser = UnionArgParser.Create() - seq { - if String.IsNullOrEmpty x.Url = false then - yield PushArgs.Url x.Url - if String.IsNullOrEmpty x.File = false then - yield PushArgs.FileName x.File - if String.IsNullOrEmpty x.ApiKey = false then - yield PushArgs.ApiKey x.ApiKey - if String.IsNullOrEmpty x.Endpoint = false then - yield PushArgs.EndPoint x.Endpoint - } - |> List.ofSeq - |> parser.CreateParseResultsOfList - |> Program.push + async { + let parser = UnionArgParser.Create() + seq { + if String.IsNullOrEmpty x.Url = false then + yield PushArgs.Url x.Url + if String.IsNullOrEmpty x.File = false then + yield PushArgs.FileName x.File + if String.IsNullOrEmpty x.ApiKey = false then + yield PushArgs.ApiKey x.ApiKey + if String.IsNullOrEmpty x.Endpoint = false then + yield PushArgs.EndPoint x.Endpoint + } + |> List.ofSeq + |> parser.CreateParseResultsOfList + |> Program.push + } |> processWithLogging x [] type RemoveCmdlet() = @@ -277,26 +303,26 @@ type RemoveCmdlet() = [] member val NoInstall = SwitchParameter() with get, set override x.ProcessRecord() = - Logging.verbose <- x.Verbose - x.SetCurrentDirectoryToLocation() - let parser = UnionArgParser.Create() - seq { - if String.IsNullOrEmpty x.NuGet = false then - yield RemoveArgs.Nuget x.NuGet - if String.IsNullOrEmpty x.Project = false then - yield RemoveArgs.Project x.Project - if x.Force.IsPresent then - yield RemoveArgs.Force - if x.Interactive.IsPresent then - yield RemoveArgs.Interactive - if x.Hard.IsPresent then - yield RemoveArgs.Hard - if x.NoInstall.IsPresent then - yield RemoveArgs.No_Install - } - |> List.ofSeq - |> parser.CreateParseResultsOfList - |> Program.remove + async { + let parser = UnionArgParser.Create() + seq { + if String.IsNullOrEmpty x.NuGet = false then + yield RemoveArgs.Nuget x.NuGet + if String.IsNullOrEmpty x.Project = false then + yield RemoveArgs.Project x.Project + if x.Force.IsPresent then + yield RemoveArgs.Force + if x.Interactive.IsPresent then + yield RemoveArgs.Interactive + if x.Hard.IsPresent then + yield RemoveArgs.Hard + if x.NoInstall.IsPresent then + yield RemoveArgs.No_Install + } + |> List.ofSeq + |> parser.CreateParseResultsOfList + |> Program.remove + } |> processWithLogging x [] type RestoreCmdlet() = @@ -306,18 +332,18 @@ type RestoreCmdlet() = [] member val ReferencesFiles = Array.empty with get, set override x.ProcessRecord() = - Logging.verbose <- x.Verbose - x.SetCurrentDirectoryToLocation() - let parser = UnionArgParser.Create() - seq { - if x.Force.IsPresent then - yield RestoreArgs.Force - for rf in x.ReferencesFiles do - yield RestoreArgs.References_Files rf - } - |> List.ofSeq - |> parser.CreateParseResultsOfList - |> Program.restore + async { + let parser = UnionArgParser.Create() + seq { + if x.Force.IsPresent then + yield RestoreArgs.Force + for rf in x.ReferencesFiles do + yield RestoreArgs.References_Files rf + } + |> List.ofSeq + |> parser.CreateParseResultsOfList + |> Program.restore + } |> processWithLogging x [] type SimplifyCmdlet() = @@ -326,16 +352,16 @@ type SimplifyCmdlet() = [] member val Interactive = SwitchParameter() with get, set override x.ProcessRecord() = - Logging.verbose <- x.Verbose - x.SetCurrentDirectoryToLocation() - let parser = UnionArgParser.Create() - seq { - if x.Interactive.IsPresent then - yield SimplifyArgs.Interactive - } - |> List.ofSeq - |> parser.CreateParseResultsOfList - |> Program.simplify + async { + let parser = UnionArgParser.Create() + seq { + if x.Interactive.IsPresent then + yield SimplifyArgs.Interactive + } + |> List.ofSeq + |> parser.CreateParseResultsOfList + |> Program.simplify + } |> processWithLogging x [] type ShowInstalledPackagesCmdlet() = @@ -346,20 +372,20 @@ type ShowInstalledPackagesCmdlet() = [] member val Silent = SwitchParameter() with get, set override x.ProcessRecord() = - Logging.verbose <- x.Verbose - x.SetCurrentDirectoryToLocation() - let parser = UnionArgParser.Create() - seq { - if x.All.IsPresent then - yield ShowInstalledPackagesArgs.All - if String.IsNullOrEmpty x.Project = false then - yield ShowInstalledPackagesArgs.Project x.Project - if x.Silent.IsPresent then - yield ShowInstalledPackagesArgs.Silent - } - |> List.ofSeq - |> parser.CreateParseResultsOfList - |> Program.showInstalledPackages + async { + let parser = UnionArgParser.Create() + seq { + if x.All.IsPresent then + yield ShowInstalledPackagesArgs.All + if String.IsNullOrEmpty x.Project = false then + yield ShowInstalledPackagesArgs.Project x.Project + if x.Silent.IsPresent then + yield ShowInstalledPackagesArgs.Silent + } + |> List.ofSeq + |> parser.CreateParseResultsOfList + |> Program.showInstalledPackages + } |> processWithLogging x [] type UpdateCmdlet() = @@ -372,21 +398,21 @@ type UpdateCmdlet() = [] member val Redirects = SwitchParameter() with get, set override x.ProcessRecord() = - Logging.verbose <- x.Verbose - x.SetCurrentDirectoryToLocation() - let parser = UnionArgParser.Create() - seq { - if String.IsNullOrEmpty x.NuGet = false then - yield UpdateArgs.Nuget x.NuGet - if String.IsNullOrEmpty x.Version = false then - yield UpdateArgs.Version x.Version - if x.Force.IsPresent then - yield UpdateArgs.Force - if x.Hard.IsPresent then - yield UpdateArgs.Hard - if x.Redirects.IsPresent then - yield UpdateArgs.Redirects - } - |> List.ofSeq - |> parser.CreateParseResultsOfList - |> Program.update \ No newline at end of file + async { + let parser = UnionArgParser.Create() + seq { + if String.IsNullOrEmpty x.NuGet = false then + yield UpdateArgs.Nuget x.NuGet + if String.IsNullOrEmpty x.Version = false then + yield UpdateArgs.Version x.Version + if x.Force.IsPresent then + yield UpdateArgs.Force + if x.Hard.IsPresent then + yield UpdateArgs.Hard + if x.Redirects.IsPresent then + yield UpdateArgs.Redirects + } + |> List.ofSeq + |> parser.CreateParseResultsOfList + |> Program.update + } |> processWithLogging x \ No newline at end of file diff --git a/src/Paket/Program.fs b/src/Paket/Program.fs index 7c25dab141..aef9207ba6 100644 --- a/src/Paket/Program.fs +++ b/src/Paket/Program.fs @@ -71,7 +71,6 @@ let processCommand<'T when 'T :> IArgParserTemplate> (commandF : ArgParseResults processWithValidation (fun _ -> true) commandF Logging.verbose <- v -Option.iter setLogFile logFile let add (results : ArgParseResults<_>) = let packageName = results.GetResult <@ AddArgs.Nuget @> @@ -252,6 +251,11 @@ let push (results : ArgParseResults<_>) = ?apiKey = results.TryGetResult <@ PushArgs.ApiKey @>) try + use consoleTrace = Logging.event.Publish |> Observable.subscribe Logging.traceToConsole + use fileTrace = + match logFile with + | Some lf -> setLogFile lf + | None -> null let parser = UnionArgParser.Create() let results = parser.Parse(inputs = args,