Skip to content

Commit 0d2648b

Browse files
authored
feat(billing): add cli command to list discounts (#3475)
1 parent c79fa16 commit 0d2648b

File tree

6 files changed

+85
-6
lines changed

6 files changed

+85
-6
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
List all discounts for an organization and usable categories/products/offers/references/regions/zones where the discount can be applied.
4+
5+
USAGE:
6+
scw billing discount list [arg=value ...]
7+
8+
ARGS:
9+
[order-by] Order discounts in the response by their description (creation_date_desc | creation_date_asc)
10+
[organization-id] ID of the organization
11+
12+
FLAGS:
13+
-h, --help help for list
14+
15+
GLOBAL FLAGS:
16+
-c, --config string The path to the config file
17+
-D, --debug Enable debug mode
18+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
19+
-p, --profile string The config profile to use

cmd/scw/testdata/test-all-usage-billing-discount-usage.golden

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
Discounts management commands.
44

55
USAGE:
6-
scw billing discount
6+
scw billing discount <command>
7+
8+
AVAILABLE COMMANDS:
9+
list List all user's discounts
710

811
FLAGS:
912
-h, --help help for discount
@@ -13,3 +16,5 @@ GLOBAL FLAGS:
1316
-D, --debug Enable debug mode
1417
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
1518
-p, --profile string The config profile to use
19+
20+
Use "scw billing discount [command] --help" for more information about a command.

docs/commands/billing.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
This API allows you to query your consumption.
44

55
- [Discounts management commands](#discounts-management-commands)
6+
- [List all user's discounts](#list-all-user's-discounts)
67
- [Invoices management commands](#invoices-management-commands)
78
- [Download an invoice](#download-an-invoice)
89
- [List invoices](#list-invoices)
@@ -12,15 +13,26 @@ This API allows you to query your consumption.
1213

1314
Discounts management commands.
1415

15-
Discounts management commands.
16+
17+
### List all user's discounts
18+
19+
List all discounts for an organization and usable categories/products/offers/references/regions/zones where the discount can be applied.
1620

1721
**Usage:**
1822

1923
```
20-
scw billing discount
24+
scw billing discount list [arg=value ...]
2125
```
2226

2327

28+
**Args:**
29+
30+
| Name | | Description |
31+
|------|---|-------------|
32+
| order-by | One of: `creation_date_desc`, `creation_date_asc` | Order discounts in the response by their description |
33+
| organization-id | | ID of the organization |
34+
35+
2436

2537
## Invoices management commands
2638

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ require (
2424
github.com/moby/buildkit v0.11.6
2525
github.com/opencontainers/go-digest v1.0.0
2626
github.com/pkg/errors v0.9.1
27-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.21.0.20231031124126-92880abb72d2
27+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.21.0.20231106093051-850928b9b69f
2828
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
2929
github.com/spf13/cobra v1.8.0
3030
github.com/spf13/pflag v1.0.5

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,8 @@ github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDN
490490
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
491491
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjyw0ULyrTYWeN0UNCCkmCWfjPnIA2W6oviI=
492492
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06/go.mod h1:+ePHsJ1keEjQtpvf9HHw0f4ZeJ0TLRsxhunSI2hYJSs=
493-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.21.0.20231031124126-92880abb72d2 h1:8sXDQUn4FSpxPFvrY5Ep6CI7VLrwCQvK0S6p8Zu5TkI=
494-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.21.0.20231031124126-92880abb72d2/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
493+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.21.0.20231106093051-850928b9b69f h1:UhKOUo3kwURWQz5a7KQ3XFlf7JD9t6iWM+c6EtUV2Mw=
494+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.21.0.20231106093051-850928b9b69f/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
495495
github.com/sclevine/spec v1.4.0 h1:z/Q9idDcay5m5irkZ28M7PtQM4aOISzOpj4bUPkDee8=
496496
github.com/secure-systems-lab/go-securesystemslib v0.4.0 h1:b23VGrQhTA8cN2CbBw7/FulN9fTtqYUdS5+Oxzt+DUE=
497497
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=

internal/namespaces/billing/v2alpha1/billing_cli.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func GetGeneratedCommands() *core.Commands {
2424
billingDiscount(),
2525
billingInvoiceList(),
2626
billingInvoiceDownload(),
27+
billingDiscountList(),
2728
)
2829
}
2930
func billingRoot() *core.Command {
@@ -152,3 +153,45 @@ func billingInvoiceDownload() *core.Command {
152153
},
153154
}
154155
}
156+
157+
func billingDiscountList() *core.Command {
158+
return &core.Command{
159+
Short: `List all user's discounts`,
160+
Long: `List all discounts for an organization and usable categories/products/offers/references/regions/zones where the discount can be applied.`,
161+
Namespace: "billing",
162+
Resource: "discount",
163+
Verb: "list",
164+
// Deprecated: false,
165+
ArgsType: reflect.TypeOf(billing.ListDiscountsRequest{}),
166+
ArgSpecs: core.ArgSpecs{
167+
{
168+
Name: "order-by",
169+
Short: `Order discounts in the response by their description`,
170+
Required: false,
171+
Deprecated: false,
172+
Positional: false,
173+
EnumValues: []string{"creation_date_desc", "creation_date_asc"},
174+
},
175+
{
176+
Name: "organization-id",
177+
Short: `ID of the organization`,
178+
Required: false,
179+
Deprecated: false,
180+
Positional: false,
181+
},
182+
},
183+
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
184+
request := args.(*billing.ListDiscountsRequest)
185+
186+
client := core.ExtractClient(ctx)
187+
api := billing.NewAPI(client)
188+
opts := []scw.RequestOption{scw.WithAllPages()}
189+
resp, err := api.ListDiscounts(request, opts...)
190+
if err != nil {
191+
return nil, err
192+
}
193+
return resp.Discounts, nil
194+
195+
},
196+
}
197+
}

0 commit comments

Comments
 (0)