Skip to content

Commit ba0bac4

Browse files
committed
feat: add billing commands for cost summaries and resource listing
Implements 'upctl billing' commands to view billing information: ## billing summary View cost summary by category with flexible period options: - Named periods: 'month', 'day', 'quarter', 'year', 'last month' - Relative periods: '3months' (3 months ago), '2weeks' (2 weeks ago) - Relative from date: '2months from 2024-06', '+3months from 2024-01' - Direct format: 'YYYY-MM' - Optional --resource filter for specific resource UUID - Optional --detailed flag for full breakdown ## billing list List detailed billing with resource names: - Fetches and displays resource names (servers, storage) - Same flexible --period options as summary - --match flag for name filtering (case-insensitive) - --category flag to filter by resource type - Shows both UUID and name for identification Both commands: - Default to current month if period not specified - Support JSON/YAML output for scripting - Use existing GetBillingSummary API endpoint Addresses #339
1 parent 2590f76 commit ba0bac4

File tree

5 files changed

+850
-0
lines changed

5 files changed

+850
-0
lines changed

internal/commands/base/base.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/UpCloudLtd/upcloud-cli/v3/internal/commands/account/token"
88
"github.com/UpCloudLtd/upcloud-cli/v3/internal/commands/all"
99
"github.com/UpCloudLtd/upcloud-cli/v3/internal/commands/auditlog"
10+
"github.com/UpCloudLtd/upcloud-cli/v3/internal/commands/billing"
1011
"github.com/UpCloudLtd/upcloud-cli/v3/internal/commands/database"
1112
databaseindex "github.com/UpCloudLtd/upcloud-cli/v3/internal/commands/database/index"
1213
databaseproperties "github.com/UpCloudLtd/upcloud-cli/v3/internal/commands/database/properties"
@@ -145,6 +146,11 @@ func BuildCommands(rootCmd *cobra.Command, conf *config.Config) {
145146
commands.BuildCommand(token.ShowCommand(), tokenCommand.Cobra(), conf)
146147
commands.BuildCommand(token.DeleteCommand(), tokenCommand.Cobra(), conf)
147148

149+
// Billing
150+
billingCommand := commands.BuildCommand(billing.BaseBillingCommand(), rootCmd, conf)
151+
commands.BuildCommand(billing.SummaryCommand(), billingCommand.Cobra(), conf)
152+
commands.BuildCommand(billing.ListCommand(), billingCommand.Cobra(), conf)
153+
148154
// Zone
149155
zoneCommand := commands.BuildCommand(zone.BaseZoneCommand(), rootCmd, conf)
150156
commands.BuildCommand(zone.ListCommand(), zoneCommand.Cobra(), conf)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package billing
2+
3+
import (
4+
"github.com/UpCloudLtd/upcloud-cli/v3/internal/commands"
5+
)
6+
7+
// BaseBillingCommand creates the base 'billing' command
8+
func BaseBillingCommand() commands.Command {
9+
return &billingCommand{commands.New("billing", "Manage billing and view cost summaries")}
10+
}
11+
12+
type billingCommand struct {
13+
*commands.BaseCommand
14+
}
15+
16+
// InitCommand implements Command.InitCommand
17+
func (b *billingCommand) InitCommand() {
18+
b.Cobra().Aliases = []string{"bill"}
19+
}

0 commit comments

Comments
 (0)