/
remove_command.go
82 lines (69 loc) · 1.79 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package teams
import (
"github.com/jmatsu/dpg/api"
"github.com/jmatsu/dpg/api/request/apps/teams/remove"
"github.com/jmatsu/dpg/command"
"github.com/jmatsu/dpg/command/apps"
"github.com/jmatsu/dpg/command/organizations/teams"
"gopkg.in/urfave/cli.v2"
)
func RemoveCommand() *cli.Command {
return &cli.Command{
Name: "remove",
Usage: "Removed a team from the specified application",
Action: command.AuthorizedCommandAction(NewRemoveCommand),
Flags: removeFlags(),
}
}
type removeCommand struct {
endpoint *api.OrganizationAppTeamsEndpoint
requestBody *remove.Request
}
func NewRemoveCommand(c *cli.Context) (command.Command, error) {
platform, err := apps.GetAppPlatform(c)
if err != nil {
return nil, err
}
cmd := removeCommand{
endpoint: &api.OrganizationAppTeamsEndpoint{
BaseURL: api.EndpointURL,
OrganizationName: apps.GetAppOwnerName(c),
AppId: apps.GetAppId(c),
AppPlatform: platform,
TeamName: teams.GetTeamName(c),
},
requestBody: &remove.Request{},
}
if err := cmd.VerifyInput(); err != nil {
return nil, err
}
return cmd, nil
}
/*
Endpoint:
organization name is required
app id is required
app platform is required
team name is required
Parameters:
none
*/
func (cmd removeCommand) VerifyInput() error {
if err := apps.RequireAppOwnerName(cmd.endpoint.OrganizationName); err != nil {
return err
}
if err := apps.RequireAppId(cmd.endpoint.AppId); err != nil {
return err
}
if err := teams.RequireTeamName(cmd.endpoint.TeamName); 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
}
}