-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReadCoffeeBalance.ps1
48 lines (41 loc) · 1.54 KB
/
ReadCoffeeBalance.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# > Get vs. Read
# : The Get verb is used to retrieve a resource, such as a file. The Read verb is used to get information from a source, such as a file.
# -> https://docs.microsoft.com/en-us/powershell/developer/cmdlet/approved-verbs-for-windows-powershell-commands
# Since we are technically _reading_ the balance from the tracker file, verb will be read.
function Read-CoffeeBalance {
<#
.Synopsis
Reads the final balance of a coffee tracker file.
.Description
Reads the final balance of a coffee tracker file.
If the -Pretty switch is used, no output is sent to STDOUT.
Output is redirected to the Console and to stream 6.
.Example
Read-CoffeeBalance
.Example
Read-CoffeeBalance -Pretty
.Example
Read-CoffeeBalance -Pretty -Path 'somecoffeefile.csv'
.Inputs
System.String
.Outputs
System.Int32
.Notes
#>
[CmdletBinding()]
param (
# Output 'Beautifully'. If you want to capture this to output, use -InformationVariable, -InformationAction, or redirect the number 6 stream to output: `6>&1`.
[Parameter()]
[Alias('ConsoleOutput')]
[switch] $Pretty,
# Specifies a path to one or more locations.
[Parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)]
[Alias('PSPath')]
[ValidateScript({ Assert-Path $_ })]
[string] $Path = $Default.TrackerPath
)
process {
$data = Import-Csv $Path
Write-Balance $data[-1].Balance -Pretty:$Pretty
}
}