-
Notifications
You must be signed in to change notification settings - Fork 1
/
remove_command.go
67 lines (57 loc) · 1.52 KB
/
remove_command.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package shared_teams
import (
"github.com/jmatsu/dpg/api"
"github.com/jmatsu/dpg/api/request/enterprises/shared_teams/remove"
"github.com/jmatsu/dpg/command"
"github.com/jmatsu/dpg/command/enterprises"
"gopkg.in/urfave/cli.v2"
)
func RemoveCommand() *cli.Command {
return &cli.Command{
Name: "remove",
Usage: "Remove a shared team from the specified enterprise",
Action: command.AuthorizedCommandAction(NewRemoveCommand),
Flags: removeFlags(),
}
}
type removeCommand struct {
endpoint *api.EnterpriseSharedTeamsEndpoint
requestBody *remove.Request
}
func NewRemoveCommand(c *cli.Context) (command.Command, error) {
cmd := removeCommand{
endpoint: &api.EnterpriseSharedTeamsEndpoint{
BaseURL: api.EndpointURL,
EnterpriseName: enterprises.GetEnterpriseName(c),
SharedTeamName: GetSharedTeamName(c),
},
requestBody: &remove.Request{},
}
if err := cmd.VerifyInput(); err != nil {
return nil, err
}
return cmd, nil
}
/*
Endpoint:
enterprise name is required
shared team name is required
Parameters:
none
*/
func (cmd removeCommand) VerifyInput() error {
if err := enterprises.RequireEnterpriseName(cmd.endpoint.EnterpriseName); err != nil {
return err
}
if err := RequireSharedTeamName(cmd.endpoint.SharedTeamName); err != nil {
return err
}
return nil
}
func (cmd removeCommand) Run(authorization *api.Authorization) (string, error) {
if bytes, err := cmd.endpoint.DeleteRequest(*authorization, *cmd.requestBody); err != nil {
return "", err
} else {
return string(bytes), nil
}
}