Skip to content

Commit

Permalink
added argument completers related to installed packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron Taggart committed Jun 22, 2015
1 parent 8cf865d commit 98b8828
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 33 deletions.
13 changes: 13 additions & 0 deletions src/Paket.PowerShell/ArgumentTabCompletion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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}'
44 changes: 12 additions & 32 deletions src/Paket.PowerShell/PowerShell.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

[<AutoOpen>]
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<PaketOutput> -> unit) =
/// runs the async computation and then a continuation on the result
let runWithLogging (cmdlet: PSCmdlet) (computation: Async<'T>) (cont: EventSink<PaketOutput> -> 'T -> unit) =
Environment.CurrentDirectory <- cmdlet.SessionState.Path.CurrentFileSystemLocation.Path
Logging.verbose <- cmdlet.Verbose
use sink = new EventSink<PaketOutput>()
Expand All @@ -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
Expand All @@ -47,31 +49,9 @@ module PaketPs =

sink.Drain()

/// runs the async computation, but no continuation is needed
let processWithLogging (cmdlet:PSCmdlet) (computation:Async<unit>) =
Environment.CurrentDirectory <- cmdlet.SessionState.Path.CurrentFileSystemLocation.Path
Logging.verbose <- cmdlet.Verbose
use sink = new EventSink<Logging.Trace>()

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 _ _ -> ())

[<Cmdlet("Paket", "Add")>]
type Add() =
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Paket.PowerShell/init.ps1
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
param($installPath, $toolsPath, $package)
Import-Module (Join-Path $toolsPath 'Paket.PowerShell\Paket.PowerShell.dll') -DisableNameChecking
Import-Module (Join-Path $toolsPath 'Paket.PowerShell\Paket.PowerShell.psd1') -DisableNameChecking

0 comments on commit 98b8828

Please sign in to comment.