This repository has been archived by the owner on Sep 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
orders.go
78 lines (69 loc) · 1.86 KB
/
orders.go
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package orders
import (
"flag"
"strings"
"github.com/abiosoft/ishell"
"github.com/cpu/acmeshell/acme/resources"
"github.com/cpu/acmeshell/shell/commands"
)
func init() {
commands.RegisterCommand(
&ishell.Cmd{
Name: "orders",
Help: "Show ACME orders created in this session by the active account",
LongHelp: `TODO(@cpu): write this`,
Func: ordersHandler,
},
nil)
}
type ordersOptions struct {
printID bool
printIdentifiers bool
status string
}
func ordersHandler(c *ishell.Context) {
opts := ordersOptions{}
ordersFlags := flag.NewFlagSet("orders", flag.ContinueOnError)
ordersFlags.BoolVar(&opts.printID, "showID", true, "Print order IDs")
ordersFlags.BoolVar(&opts.printIdentifiers, "showIdents", true, "Print order identifiers")
ordersFlags.StringVar(&opts.status, "status", "", "Print orders only if they are in the given status")
if _, err := commands.ParseFlagSetArgs(c.Args, ordersFlags); err != nil {
return
}
if !opts.printID && !opts.printIdentifiers {
c.Printf("orders: -showID and -showIdents can not both be false\n")
return
}
client := commands.GetClient(c)
orders := client.ActiveAccount.Orders
if len(orders) == 0 {
c.Printf("orders: the active account has no orders\n")
return
}
for i, orderURL := range orders {
order := &resources.Order{
ID: orderURL,
}
err := client.UpdateOrder(order)
if err != nil {
c.Printf("orders: error getting order object: %s\n", err.Error())
return
}
if opts.status != "" && order.Status != opts.status {
continue
}
c.Printf("%3d)", i)
if opts.printID {
c.Printf("\t%#q", order.ID)
}
if opts.printIdentifiers {
var domains []string
for _, d := range order.Identifiers {
domains = append(domains, d.Value)
}
c.Printf("\t%s", strings.Join(domains, ","))
}
c.Printf("\t%s", order.Status)
c.Printf("\n")
}
}