-
Notifications
You must be signed in to change notification settings - Fork 18
/
deletecategories.go
39 lines (32 loc) · 945 Bytes
/
deletecategories.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package deletecategories
import (
"fmt"
"github.com/spf13/cobra"
"github.com/sagan/ptool/client"
"github.com/sagan/ptool/cmd"
)
var command = &cobra.Command{
Use: "deletecategories {client} {category}...",
Aliases: []string{"delcats"},
Annotations: map[string]string{"cobra-prompt-dynamic-suggestions": "deletecategories"},
Short: "Delete categories from client.",
Long: `Delete categories from client.`,
Args: cobra.MatchAll(cobra.MinimumNArgs(2), cobra.OnlyValidArgs),
RunE: deletecategories,
}
func init() {
cmd.RootCmd.AddCommand(command)
}
func deletecategories(cmd *cobra.Command, args []string) error {
clientName := args[0]
categories := args[1:]
clientInstance, err := client.CreateClient(clientName)
if err != nil {
return fmt.Errorf("failed to create client: %v", err)
}
err = clientInstance.DeleteCategories(categories)
if err != nil {
return err
}
return nil
}