@@ -168,6 +168,139 @@ function Format-ProjectItem{
168168 }
169169} Export-ModuleMember - Function Format-ProjectItem
170170
171+ function Show-ProjectItem {
172+ [CmdletBinding ()]
173+ [Alias (" shpi" )]
174+ param (
175+ [Parameter (ValueFromPipeline )][string ]$ItemId ,
176+ [Parameter ()][array []]$FieldsToShow
177+ )
178+
179+ process {
180+
181+ $item = Get-ProjectItem - ItemId $ItemId
182+
183+ if ($null -eq $item ){
184+ " Item not found" | Write-MyError
185+ return $null
186+ }
187+
188+ if (-not $FieldsToShow ){
189+ $statusColor = getStatusColor($item.Status )
190+ $FieldsToShow = @ (
191+ @ (@ {Name = " Status" ; Color = $statusColor })
192+ )
193+ }
194+
195+ # Before all
196+ addJumpLine
197+
198+ # title bar
199+ # ($item.RepositoryOwner + "/") | write -Color Cyan
200+ # ($item.RepositoryName) | write -Color Cyan
201+ $item.number | write - Color Cyan - PreFix " #"
202+ addSpace
203+ $item.Title | write - Color Yellow - BetweenQuotes
204+
205+ addJumpLine
206+
207+ # URL
208+ $item.url | write - Color White
209+
210+ # Fields by line
211+ if ($FieldsToShow ){
212+ addJumpLine
213+ foreach ($line in $FieldsToShow ){
214+ addJumpLine
215+ ShowAttribLine - AttributesToShow $line - Item $item
216+ }
217+ }
218+
219+ addJumpLine
220+
221+ # Body
222+ addJumpLine ; " --- Body ---" | write Cyan ; addJumpLine
223+ $item.body | write - Color Gray
224+
225+ # End of item
226+ addJumpLine ; " ------------" | write Cyan ; addJumpLine
227+
228+ # ID at the end
229+ $item.id | write - Color DarkGray
230+ }
231+ } Export-ModuleMember - Function Show-ProjectItem - Alias(" shpi" )
232+
233+ function getStatusColor {
234+ param (
235+ [string ]$status
236+ )
237+
238+ switch ($status.ToLower ()) {
239+ " Todo" { return " Green" }
240+ " Done" { return " DarkMagenta" }
241+ " In Progress" { return " Yellow" }
242+ default { return " Gray" }
243+ }
244+ }
245+
246+ function write {
247+ param (
248+ [Parameter (Position = 1 )][string ]$color ,
249+ [Parameter (Position = 2 , ValueFromPipeline )][string ]$text ,
250+ [Parameter ()][switch ]$BetweenQuotes ,
251+ [Parameter ()][string ]$PreFix ,
252+ [Parameter ()][string ]$DefaultValue = " (empty)"
253+
254+ )
255+ process {
256+
257+ if ([string ]::IsNullOrWhiteSpace($text )){
258+ $text = $DefaultValue
259+ }
260+
261+ if ($BetweenQuotes ){
262+ $text = " "" $text "" "
263+ }
264+
265+ if ($PreFix ){
266+ $text = $PreFix + $text
267+ }
268+
269+
270+ $text | Write-ToConsole - Color $color - NoNewLine
271+ }
272+ }
273+ function addJumpLine {
274+ Write-ToConsole - Color White
275+ }
276+ function addSpace {
277+ " " | Write-ToConsole - Color Cyan - NoNewline
278+ }
279+ function ShowAttribLine {
280+ param (
281+ [array ]$AttributesToShow ,
282+ [object ]$item
283+ )
284+
285+ $isfirst = $true
286+
287+ $AttributesToShow | ForEach-Object {
288+ $name = $_.Name
289+ $color = $_.Color
290+ $prefix = $_.Prefix
291+ $BetweenQuotes = $_.BetweenQuotes
292+
293+ $value = $item .$name
294+
295+ if (! $isfirst ){
296+ " | " | write Gray
297+ } else {
298+ $isfirst = $false
299+ }
300+
301+ $value | write $color - PreFix $prefix - BetweenQuotes:$BetweenQuotes - DefaultValue " <$name >"
302+ }
303+ }
171304
172305function Get-ProjectItems {
173306 [CmdletBinding ()]
0 commit comments