From 98b8828e5b54326971306539aefb046a6a33cd0e Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Sun, 21 Jun 2015 22:42:12 -0700 Subject: [PATCH] added argument completers related to installed packages --- .../ArgumentTabCompletion.ps1 | 13 ++++++ src/Paket.PowerShell/PowerShell.fs | 44 +++++-------------- src/Paket.PowerShell/init.ps1 | 2 +- 3 files changed, 26 insertions(+), 33 deletions(-) diff --git a/src/Paket.PowerShell/ArgumentTabCompletion.ps1 b/src/Paket.PowerShell/ArgumentTabCompletion.ps1 index 47f4fafedb..6c907dcff9 100644 --- a/src/Paket.PowerShell/ArgumentTabCompletion.ps1 +++ b/src/Paket.PowerShell/ArgumentTabCompletion.ps1 @@ -26,11 +26,24 @@ $findPackageVersions = { } } +$showInstalledPackages = { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) + Paket-ShowInstalledPackages | % { + $name = $_.Name + createCompletionResult $name $name $name | write + } +} + # create and add $global:options to the list of completers # http://www.powertheshell.com/dynamicargumentcompletion/ if (-not $global:options) { $global:options = @{CustomArgumentCompleters = @{};NativeArgumentCompleters = @{}}} $global:options['CustomArgumentCompleters']['Paket-Add:NuGet'] = $findPackages $global:options['CustomArgumentCompleters']['Paket-Add:Version'] = $findPackageVersions +$global:options['CustomArgumentCompleters']['Paket-Update:NuGet'] = $showInstalledPackages +$global:options['CustomArgumentCompleters']['Paket-Update:Version'] = $findPackageVersions +$global:options['CustomArgumentCompleters']['Paket-Remove:NuGet'] = $showInstalledPackages +$global:options['CustomArgumentCompleters']['Paket-FindPackageVersions:Name'] = $findPackages +$global:options['CustomArgumentCompleters']['Paket-FindRefs:NuGet'] = $showInstalledPackages $function:tabexpansion2 = $function:tabexpansion2 -replace 'End\r\n{','End { if ($null -ne $options) { $options += $global:options} else {$options = $global:options}' \ No newline at end of file diff --git a/src/Paket.PowerShell/PowerShell.fs b/src/Paket.PowerShell/PowerShell.fs index f1ccddd9e4..150aa81c42 100644 --- a/src/Paket.PowerShell/PowerShell.fs +++ b/src/Paket.PowerShell/PowerShell.fs @@ -7,16 +7,18 @@ open Paket.Commands open Nessos.UnionArgParser open System +// types exposed publicly by sending to output +type Package = { Name: string; Version: string } + [] module PaketPs = - type Package = { Name: string; Version: string } - type PaketOutput = - | Trace of Logging.Trace - | Package of Package + | Trace of Logging.Trace + | Package of Package - let runWithLogging (cmdlet:PSCmdlet) (computation:Async<'T>) (cont:'T -> EventSink -> unit) = + /// runs the async computation and then a continuation on the result + let runWithLogging (cmdlet: PSCmdlet) (computation: Async<'T>) (cont: EventSink -> 'T -> unit) = Environment.CurrentDirectory <- cmdlet.SessionState.Path.CurrentFileSystemLocation.Path Logging.verbose <- cmdlet.Verbose use sink = new EventSink() @@ -38,7 +40,7 @@ module PaketPs = // prevent an exception from killing the thread, PS thread, and PS exe try let! v = computation - cont v sink + cont sink v with | ex -> Logging.traceWarn ex.Message finally @@ -47,31 +49,9 @@ module PaketPs = sink.Drain() + /// runs the async computation, but no continuation is needed let processWithLogging (cmdlet:PSCmdlet) (computation:Async) = - 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() - // prevent an exception from killing the thread, PS thread, and PS exe - try - do! computation - with - | ex -> Logging.traceWarn ex.Message - finally - sink.StopFill() - } |> Async.Start - - sink.Drain() + runWithLogging cmdlet computation (fun _ _ -> ()) [] type Add() = @@ -418,9 +398,9 @@ type ShowInstalledPackagesCmdlet() = } runWithLogging x computation - (fun packages output -> + (fun sink packages -> for name,version in packages do - output.Add + sink.Add (PaketOutput.Package {Name=name; Version=version}) (fun po -> match po with diff --git a/src/Paket.PowerShell/init.ps1 b/src/Paket.PowerShell/init.ps1 index e9e2cf65f9..dd4b485d9d 100644 --- a/src/Paket.PowerShell/init.ps1 +++ b/src/Paket.PowerShell/init.ps1 @@ -1,2 +1,2 @@ param($installPath, $toolsPath, $package) -Import-Module (Join-Path $toolsPath 'Paket.PowerShell\Paket.PowerShell.dll') -DisableNameChecking \ No newline at end of file +Import-Module (Join-Path $toolsPath 'Paket.PowerShell\Paket.PowerShell.psd1') -DisableNameChecking \ No newline at end of file