Skip to content

Commit

Permalink
feat(billing): add cli command to list discounts (#3475)
Browse files Browse the repository at this point in the history
  • Loading branch information
scaleway-bot authored Nov 7, 2023
1 parent c79fa16 commit 0d2648b
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 6 deletions.
19 changes: 19 additions & 0 deletions cmd/scw/testdata/test-all-usage-billing-discount-list-usage.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
List all discounts for an organization and usable categories/products/offers/references/regions/zones where the discount can be applied.

USAGE:
scw billing discount list [arg=value ...]

ARGS:
[order-by] Order discounts in the response by their description (creation_date_desc | creation_date_asc)
[organization-id] ID of the organization

FLAGS:
-h, --help help for list

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
Discounts management commands.

USAGE:
scw billing discount
scw billing discount <command>

AVAILABLE COMMANDS:
list List all user's discounts

FLAGS:
-h, --help help for discount
Expand All @@ -13,3 +16,5 @@ GLOBAL FLAGS:
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use

Use "scw billing discount [command] --help" for more information about a command.
16 changes: 14 additions & 2 deletions docs/commands/billing.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This API allows you to query your consumption.

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

Discounts management commands.

Discounts management commands.

### List all user's discounts

List all discounts for an organization and usable categories/products/offers/references/regions/zones where the discount can be applied.

**Usage:**

```
scw billing discount
scw billing discount list [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| order-by | One of: `creation_date_desc`, `creation_date_asc` | Order discounts in the response by their description |
| organization-id | | ID of the organization |



## Invoices management commands

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/moby/buildkit v0.11.6
github.com/opencontainers/go-digest v1.0.0
github.com/pkg/errors v0.9.1
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.21.0.20231031124126-92880abb72d2
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.21.0.20231106093051-850928b9b69f
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,8 @@ github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDN
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjyw0ULyrTYWeN0UNCCkmCWfjPnIA2W6oviI=
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06/go.mod h1:+ePHsJ1keEjQtpvf9HHw0f4ZeJ0TLRsxhunSI2hYJSs=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.21.0.20231031124126-92880abb72d2 h1:8sXDQUn4FSpxPFvrY5Ep6CI7VLrwCQvK0S6p8Zu5TkI=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.21.0.20231031124126-92880abb72d2/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.21.0.20231106093051-850928b9b69f h1:UhKOUo3kwURWQz5a7KQ3XFlf7JD9t6iWM+c6EtUV2Mw=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.21.0.20231106093051-850928b9b69f/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
github.com/sclevine/spec v1.4.0 h1:z/Q9idDcay5m5irkZ28M7PtQM4aOISzOpj4bUPkDee8=
github.com/secure-systems-lab/go-securesystemslib v0.4.0 h1:b23VGrQhTA8cN2CbBw7/FulN9fTtqYUdS5+Oxzt+DUE=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
Expand Down
43 changes: 43 additions & 0 deletions internal/namespaces/billing/v2alpha1/billing_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func GetGeneratedCommands() *core.Commands {
billingDiscount(),
billingInvoiceList(),
billingInvoiceDownload(),
billingDiscountList(),
)
}
func billingRoot() *core.Command {
Expand Down Expand Up @@ -152,3 +153,45 @@ func billingInvoiceDownload() *core.Command {
},
}
}

func billingDiscountList() *core.Command {
return &core.Command{
Short: `List all user's discounts`,
Long: `List all discounts for an organization and usable categories/products/offers/references/regions/zones where the discount can be applied.`,
Namespace: "billing",
Resource: "discount",
Verb: "list",
// Deprecated: false,
ArgsType: reflect.TypeOf(billing.ListDiscountsRequest{}),
ArgSpecs: core.ArgSpecs{
{
Name: "order-by",
Short: `Order discounts in the response by their description`,
Required: false,
Deprecated: false,
Positional: false,
EnumValues: []string{"creation_date_desc", "creation_date_asc"},
},
{
Name: "organization-id",
Short: `ID of the organization`,
Required: false,
Deprecated: false,
Positional: false,
},
},
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
request := args.(*billing.ListDiscountsRequest)

client := core.ExtractClient(ctx)
api := billing.NewAPI(client)
opts := []scw.RequestOption{scw.WithAllPages()}
resp, err := api.ListDiscounts(request, opts...)
if err != nil {
return nil, err
}
return resp.Discounts, nil

},
}
}

0 comments on commit 0d2648b

Please sign in to comment.