Skip to content

Commit 53902e9

Browse files
committed
feat: Add missing support tickets features
Signed-off-by: Arthur Amstutz <arthur.amstutz@gmail.com>
1 parent eed21b6 commit 53902e9

File tree

5 files changed

+131
-0
lines changed

5 files changed

+131
-0
lines changed

doc/ovhcloud_support-tickets.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ Retrieve information and manage your support tickets
3232
* [ovhcloud](ovhcloud.md) - CLI to manage your OVHcloud services
3333
* [ovhcloud support-tickets get](ovhcloud_support-tickets_get.md) - Retrieve information of a specific support ticket
3434
* [ovhcloud support-tickets list](ovhcloud_support-tickets_list.md) - List your support tickets
35+
* [ovhcloud support-tickets messages](ovhcloud_support-tickets_messages.md) - List messages for a support ticket
36+
* [ovhcloud support-tickets reply](ovhcloud_support-tickets_reply.md) - Reply to a support ticket
3537

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
## ovhcloud support-tickets messages
2+
3+
List messages for a support ticket
4+
5+
```
6+
ovhcloud support-tickets messages <ticket_id> [flags]
7+
```
8+
9+
### Options
10+
11+
```
12+
--filter stringArray Filter results by any property using https://github.com/PaesslerAG/gval syntax
13+
Examples:
14+
--filter 'state="running"'
15+
--filter 'name=~"^my.*"'
16+
--filter 'nested.property.subproperty>10'
17+
--filter 'startDate>="2023-12-01"'
18+
--filter 'name=~"something" && nbField>10'
19+
-h, --help help for messages
20+
```
21+
22+
### Options inherited from parent commands
23+
24+
```
25+
-d, --debug Activate debug mode (will log all HTTP requests details)
26+
-e, --ignore-errors Ignore errors in API calls when it is not fatal to the execution
27+
-o, --output string Output format: json, yaml, interactive, or a custom format expression (using https://github.com/PaesslerAG/gval syntax)
28+
Examples:
29+
--output json
30+
--output yaml
31+
--output interactive
32+
--output 'id' (to extract a single field)
33+
--output 'nested.field.subfield' (to extract a nested field)
34+
--output '[id, "name"]' (to extract multiple fields as an array)
35+
--output '{"newKey": oldKey, "otherKey": nested.field}' (to extract and rename fields in an object)
36+
--output 'name+","+type' (to extract and concatenate fields in a string)
37+
--output '(nbFieldA + nbFieldB) * 10' (to compute values from numeric fields)
38+
--profile string Use a specific profile from the configuration file
39+
```
40+
41+
### SEE ALSO
42+
43+
* [ovhcloud support-tickets](ovhcloud_support-tickets.md) - Retrieve information and manage your support tickets
44+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
## ovhcloud support-tickets reply
2+
3+
Reply to a support ticket
4+
5+
```
6+
ovhcloud support-tickets reply <ticket_id> [flags]
7+
```
8+
9+
### Options
10+
11+
```
12+
--body string Text body of the ticket reply
13+
-h, --help help for reply
14+
```
15+
16+
### Options inherited from parent commands
17+
18+
```
19+
-d, --debug Activate debug mode (will log all HTTP requests details)
20+
-e, --ignore-errors Ignore errors in API calls when it is not fatal to the execution
21+
-o, --output string Output format: json, yaml, interactive, or a custom format expression (using https://github.com/PaesslerAG/gval syntax)
22+
Examples:
23+
--output json
24+
--output yaml
25+
--output interactive
26+
--output 'id' (to extract a single field)
27+
--output 'nested.field.subfield' (to extract a nested field)
28+
--output '[id, "name"]' (to extract multiple fields as an array)
29+
--output '{"newKey": oldKey, "otherKey": nested.field}' (to extract and rename fields in an object)
30+
--output 'name+","+type' (to extract and concatenate fields in a string)
31+
--output '(nbFieldA + nbFieldB) * 10' (to compute values from numeric fields)
32+
--profile string Use a specific profile from the configuration file
33+
```
34+
35+
### SEE ALSO
36+
37+
* [ovhcloud support-tickets](ovhcloud_support-tickets.md) - Retrieve information and manage your support tickets
38+

internal/cmd/supporttickets.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,26 @@ func init() {
3232
Run: supporttickets.GetSupportTickets,
3333
})
3434

35+
// Command to list messages for a support ticket
36+
supportticketsMessagesCmd := &cobra.Command{
37+
Use: "messages <ticket_id>",
38+
Aliases: []string{"msgs"},
39+
Short: "List messages for a support ticket",
40+
Args: cobra.ExactArgs(1),
41+
Run: supporttickets.ListSupportTicketMessages,
42+
}
43+
supportticketsCmd.AddCommand(withFilterFlag(supportticketsMessagesCmd))
44+
45+
// Command to reply to a support ticket
46+
supportticketsReplyCmd := &cobra.Command{
47+
Use: "reply <ticket_id>",
48+
Short: "Reply to a support ticket",
49+
Args: cobra.ExactArgs(1),
50+
Run: supporttickets.ReplySupportTicket,
51+
}
52+
supportticketsReplyCmd.Flags().StringVar(&supporttickets.ReplySpec.Body, "body", "", "Text body of the ticket reply")
53+
_ = supportticketsReplyCmd.MarkFlagRequired("body")
54+
supportticketsCmd.AddCommand(supportticketsReplyCmd)
55+
3556
rootCmd.AddCommand(supportticketsCmd)
3657
}

internal/services/supporttickets/supporttickets.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,27 @@ package supporttickets
66

77
import (
88
_ "embed"
9+
"fmt"
10+
"net/url"
911

12+
"github.com/ovh/ovhcloud-cli/internal/display"
1013
"github.com/ovh/ovhcloud-cli/internal/flags"
14+
httpLib "github.com/ovh/ovhcloud-cli/internal/http"
1115
"github.com/ovh/ovhcloud-cli/internal/services/common"
1216
"github.com/spf13/cobra"
1317
)
1418

1519
var (
1620
supportticketsColumnsToDisplay = []string{"ticketId", "serviceName", "type", "category", "state"}
21+
messagesColumnsToDisplay = []string{"messageId", "from", "creationDate", "body"}
1722

1823
//go:embed templates/supporttickets.tmpl
1924
supportticketsTemplate string
25+
26+
// ReplySpec holds the parameters for the reply command.
27+
ReplySpec struct {
28+
Body string `json:"body,omitempty"`
29+
}
2030
)
2131

2232
func ListSupportTickets(_ *cobra.Command, _ []string) {
@@ -26,3 +36,19 @@ func ListSupportTickets(_ *cobra.Command, _ []string) {
2636
func GetSupportTickets(_ *cobra.Command, args []string) {
2737
common.ManageObjectRequest("/v1/support/tickets", args[0], supportticketsTemplate)
2838
}
39+
40+
func ListSupportTicketMessages(_ *cobra.Command, args []string) {
41+
endpoint := fmt.Sprintf("/v1/support/tickets/%s/messages", url.PathEscape(args[0]))
42+
common.ManageListRequestNoExpand(endpoint, messagesColumnsToDisplay, flags.GenericFilters)
43+
}
44+
45+
func ReplySupportTicket(_ *cobra.Command, args []string) {
46+
endpoint := fmt.Sprintf("/v1/support/tickets/%s/reply", url.PathEscape(args[0]))
47+
48+
if err := httpLib.Client.Post(endpoint, ReplySpec, nil); err != nil {
49+
display.OutputError(&flags.OutputFormatConfig, "failed to reply to ticket: %s", err)
50+
return
51+
}
52+
53+
display.OutputInfo(&flags.OutputFormatConfig, nil, "✅ Reply sent successfully")
54+
}

0 commit comments

Comments
 (0)