Skip to content

Commit

Permalink
Merge pull request #885 from ctaggart/powershell
Browse files Browse the repository at this point in the history
fixed exceptions not being logged
  • Loading branch information
forki committed Jun 21, 2015
2 parents f9f0bb3 + 0d86d20 commit b978d48
Showing 1 changed file with 48 additions and 44 deletions.
92 changes: 48 additions & 44 deletions src/Paket/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -250,54 +250,58 @@ let push (results : ArgParseResults<_>) =
?endPoint = results.TryGetResult <@ PushArgs.EndPoint @>,
?apiKey = results.TryGetResult <@ PushArgs.ApiKey @>)

try
let main() =
use consoleTrace = Logging.event.Publish |> Observable.subscribe Logging.traceToConsole
use fileTrace =
match logFile with
| Some lf -> setLogFile lf
| None -> null
let parser = UnionArgParser.Create<Command>()
let results =
parser.Parse(inputs = args,
ignoreMissing = true,
ignoreUnrecognized = true,
raiseOnUsage = false)

match results.GetAllResults() with
| [ command ] ->
let handler =
match command with
| Add -> processCommand add
| Config -> processWithValidation validateConfig config
| ConvertFromNuget -> processCommand convert
| FindRefs -> processCommand findRefs
| Init -> processCommand init
| AutoRestore -> processWithValidation validateAutoRestore autoRestore
| Install -> processCommand install
| Outdated -> processCommand outdated
| Remove -> processCommand remove
| Restore -> processCommand restore
| Simplify -> processCommand simplify
| Update -> processCommand update
| FindPackages -> processCommand findPackages
| FindPackageVersions -> processCommand findPackageVersions
| ShowInstalledPackages -> processCommand showInstalledPackages
| Pack -> processCommand pack
| Push -> processCommand push

let args = args.[1..]

handler command args
| [] ->
try
let parser = UnionArgParser.Create<Command>()
let results =
parser.Parse(inputs = args,
ignoreMissing = true,
ignoreUnrecognized = true,
raiseOnUsage = false)

match results.GetAllResults() with
| [ command ] ->
let handler =
match command with
| Add -> processCommand add
| Config -> processWithValidation validateConfig config
| ConvertFromNuget -> processCommand convert
| FindRefs -> processCommand findRefs
| Init -> processCommand init
| AutoRestore -> processWithValidation validateAutoRestore autoRestore
| Install -> processCommand install
| Outdated -> processCommand outdated
| Remove -> processCommand remove
| Restore -> processCommand restore
| Simplify -> processCommand simplify
| Update -> processCommand update
| FindPackages -> processCommand findPackages
| FindPackageVersions -> processCommand findPackageVersions
| ShowInstalledPackages -> processCommand showInstalledPackages
| Pack -> processCommand pack
| Push -> processCommand push

let args = args.[1..]

handler command args
| [] ->
Environment.ExitCode <- 1
traceError "Command was:"
traceError (" " + String.Join(" ",Environment.GetCommandLineArgs()))
parser.Usage("available commands:") |> traceError
| _ -> failwith "expected only one command"
with
| exn when not (exn :? System.NullReferenceException) ->
Environment.ExitCode <- 1
traceError "Command was:"
traceError (" " + String.Join(" ",Environment.GetCommandLineArgs()))
parser.Usage("available commands:") |> traceError
| _ -> failwith "expected only one command"
with
| exn when not (exn :? System.NullReferenceException) ->
Environment.ExitCode <- 1
traceErrorfn "Paket failed with:%s\t%s" Environment.NewLine exn.Message

if verbose then
traceErrorfn "StackTrace:%s %s" Environment.NewLine exn.StackTrace
traceErrorfn "Paket failed with:%s\t%s" Environment.NewLine exn.Message

if verbose then
traceErrorfn "StackTrace:%s %s" Environment.NewLine exn.StackTrace

main()

0 comments on commit b978d48

Please sign in to comment.