@@ -4,12 +4,13 @@ import (
44 "fmt"
55
66 "github.com/spf13/cobra"
7+ "github.com/tursodatabase/turso-cli/internal/flags"
78 "github.com/tursodatabase/turso-cli/internal/turso"
89)
910
1011func init () {
1112 invoiceCmd .AddCommand (listInvoicesCmd )
12- AddInvoiceType (listInvoicesCmd )
13+ flags . AddInvoiceType (listInvoicesCmd )
1314}
1415
1516var listInvoicesCmd = & cobra.Command {
@@ -24,12 +25,9 @@ var listInvoicesCmd = &cobra.Command{
2425 return err
2526 }
2627
27- if invoiceType == "" {
28- invoiceType = "issued"
29- }
30-
31- if invoiceType != "all" && invoiceType != "upcoming" && invoiceType != "issued" {
32- return fmt .Errorf ("invalid invoice type: %s" , invoiceType )
28+ invoiceType , err := flags .InvoiceType ()
29+ if err != nil {
30+ return err
3331 }
3432
3533 invoices , err := client .Invoices .List (invoiceType )
@@ -42,25 +40,25 @@ var listInvoicesCmd = &cobra.Command{
4240 return nil
4341 }
4442
45- printInvoiceListTable (invoices )
43+ printInvoiceTable (invoices )
4644 fmt .Println ()
4745 fmt .Println ()
48- printInvoiceListLinks (invoices )
46+ printInvoiceLinks (invoices )
4947 return nil
5048 },
5149}
5250
53- func printInvoiceListTable (invoices []turso.Invoice ) {
54- headers , data := invoiceListTable (invoices )
51+ func printInvoiceTable (invoices []turso.Invoice ) {
52+ headers , data := invoiceTable (invoices )
5553 printTable (headers , data )
5654}
5755
58- func printInvoiceListLinks (invoices []turso.Invoice ) {
59- headers , data := invoiceListLinks (invoices )
56+ func printInvoiceLinks (invoices []turso.Invoice ) {
57+ headers , data := invoiceLinks (invoices )
6058 printTable (headers , data )
6159}
6260
63- func invoiceListTable (invoices []turso.Invoice ) ([]string , [][]string ) {
61+ func invoiceTable (invoices []turso.Invoice ) ([]string , [][]string ) {
6462 headers := []string {"ID" , "Amount Due" , "Status" , "Due Date" , "Paid At" , "Payment Failed At" }
6563 data := make ([][]string , len (invoices ))
6664 for i , invoice := range invoices {
@@ -69,7 +67,7 @@ func invoiceListTable(invoices []turso.Invoice) ([]string, [][]string) {
6967 return headers , data
7068}
7169
72- func invoiceListLinks (invoices []turso.Invoice ) ([]string , [][]string ) {
70+ func invoiceLinks (invoices []turso.Invoice ) ([]string , [][]string ) {
7371 headers := []string {"ID" , "Link" }
7472 data := make ([][]string , len (invoices ))
7573 for i , invoice := range invoices {
0 commit comments