-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcmds.go
More file actions
56 lines (47 loc) · 1.06 KB
/
Copy pathcmds.go
File metadata and controls
56 lines (47 loc) · 1.06 KB
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
49
50
51
52
53
54
55
56
// Copyright (c) 2024-2026 sewn <sewn@disroot.org>
// SPDX-License-Identifier: ISC
package main
import (
"encoding/json"
"fmt"
"math"
"os"
"time"
)
type valueCmd struct {
Currency string `kong:"help='Currency rate for total conversion (e.g., USD, EUR, GBP)',default=USD"`
}
func (cmd *valueCmd) Run(c *Client) error {
items, err := c.GetCollection(c.Fan.ID)
if err != nil {
return err
}
cost, err := c.Value(c.Fan, items, cmd.Currency)
if err != nil {
return err
}
fmt.Printf("%d items = ~%.0f%s\n",
len(items), math.Ceil(cost), cmd.Currency)
return nil
}
type listCmd struct {
JSON bool `kong:"short=j,help='Output all known data using a JSON object array'"`
}
func (cmd *listCmd) Run(c *Client) error {
items, err := c.GetCollection(c.Fan.ID)
if err != nil {
return err
}
if cmd.JSON {
enc := json.NewEncoder(os.Stderr)
enc.SetIndent("", " ")
return enc.Encode(items)
}
for _, item := range items {
fmt.Printf("%-10d %s %s - %s\n",
item.ID,
item.Purchased.Format(time.DateOnly),
item.BandName, item.Title)
}
return nil
}