55 "fmt"
66
77 "github.com/softlayer/softlayer-go/datatypes"
8+ "github.com/softlayer/softlayer-go/filter"
89
910 "github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/terminal"
1011 "github.com/spf13/cobra"
@@ -20,6 +21,9 @@ type BillingItemsCommand struct {
2021 * metadata.SoftlayerCommand
2122 AccountManager managers.AccountManager
2223 Command * cobra.Command
24+ Category string
25+ Create string
26+ Ordered string
2327}
2428
2529func NewBillingItemsCommand (sl * metadata.SoftlayerCommand ) * BillingItemsCommand {
@@ -35,6 +39,9 @@ func NewBillingItemsCommand(sl *metadata.SoftlayerCommand) *BillingItemsCommand
3539 return thisCmd .Run (args )
3640 },
3741 }
42+ cobraCmd .Flags ().StringVar (& thisCmd .Category , "category" , "" , T ("Category name." ))
43+ cobraCmd .Flags ().StringVar (& thisCmd .Create , "create" , "" , T ("The date the billing item was created (YYYY-MM-DD)." ))
44+ cobraCmd .Flags ().StringVar (& thisCmd .Ordered , "ordered" , "" , T ("Name that ordered the item." ))
3845 thisCmd .Command = cobraCmd
3946 return thisCmd
4047}
@@ -43,16 +50,27 @@ func (cmd *BillingItemsCommand) Run(args []string) error {
4350
4451 outputFormat := cmd .GetOutputFlag ()
4552
46- mask := "mask[orderItem[id,order[id,userRecord[id,email,displayName,userStatus]]],nextInvoiceTotalRecurringAmount,location, hourlyFlag]"
47- billingItems , err := cmd .AccountManager .GetBillingItems (mask )
53+ objectMask := "mask[orderItem[id,order[id,userRecord[id,email,displayName,userStatus]]],nextInvoiceTotalRecurringAmount,location, hourlyFlag]"
54+
55+ objectFilter := filter .New ()
56+ objectFilter = append (objectFilter , filter .Path ("allTopLevelBillingItems.id" ).OrderBy ("ASC" ))
57+ objectFilter = append (objectFilter , filter .Path ("allTopLevelBillingItems.cancellationDate" ).IsNull ())
58+ if cmd .Category != "" {
59+ objectFilter = append (objectFilter , filter .Path ("allTopLevelBillingItems.categoryCode" ).Eq (cmd .Category ))
60+ }
61+ if cmd .Create != "" {
62+ objectFilter = append (objectFilter , filter .Path ("allTopLevelBillingItems.createDate" ).Contains (cmd .Create ))
63+ }
64+
65+ billingItems , err := cmd .AccountManager .GetBillingItems (objectMask , objectFilter .Build ())
4866 if err != nil {
4967 return errors .NewAPIError (T ("Failed to get billing items." ), err .Error (), 2 )
5068 }
51- PrintBillingItems (billingItems , cmd .UI , outputFormat )
69+ PrintBillingItems (billingItems , cmd .UI , cmd . Ordered , outputFormat )
5270 return nil
5371}
5472
55- func PrintBillingItems (billingItems []datatypes.Billing_Item , ui terminal.UI , outputFormat string ) {
73+ func PrintBillingItems (billingItems []datatypes.Billing_Item , ui terminal.UI , orderedFilter string , outputFormat string ) {
5674 bufEvent := new (bytes.Buffer )
5775 table := terminal .NewTable (bufEvent , []string {
5876 T ("Id" ),
@@ -74,6 +92,11 @@ func PrintBillingItems(billingItems []datatypes.Billing_Item, ui terminal.UI, ou
7492 if billingItems .OrderItem != nil {
7593 OrderedBy = utils .FormatStringPointer (billingItems .OrderItem .Order .UserRecord .DisplayName )
7694 }
95+
96+ if orderedFilter != "" && orderedFilter != OrderedBy {
97+ continue
98+ }
99+
77100 table .Add (
78101 utils .FormatIntPointer (billingItems .Id ),
79102 utils .FormatSLTimePointer (billingItems .CreateDate ),
0 commit comments