mirror of
https://gitea.com/gitea/tea.git
synced 2025-07-05 23:00:23 +02:00

I tested this somewhat, but I haven't been using the cli before so I'm not sure if there are changes - there shouldn't be though. Reviewed-on: https://gitea.com/gitea/tea/pulls/760 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: TheFox0x7 <thefox0x7@gmail.com> Co-committed-by: TheFox0x7 <thefox0x7@gmail.com>
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package organizations
|
|
|
|
import (
|
|
stdctx "context"
|
|
|
|
"code.gitea.io/sdk/gitea"
|
|
"code.gitea.io/tea/cmd/flags"
|
|
"code.gitea.io/tea/modules/context"
|
|
"code.gitea.io/tea/modules/print"
|
|
"github.com/urfave/cli/v3"
|
|
)
|
|
|
|
// CmdOrganizationList represents a sub command of organizations to list users organizations
|
|
var CmdOrganizationList = cli.Command{
|
|
Name: "list",
|
|
Aliases: []string{"ls"},
|
|
Usage: "List Organizations",
|
|
Description: "List users organizations",
|
|
ArgsUsage: " ", // command does not accept arguments
|
|
Action: RunOrganizationList,
|
|
Flags: append([]cli.Flag{
|
|
&flags.PaginationPageFlag,
|
|
&flags.PaginationLimitFlag,
|
|
}, flags.AllDefaultFlags...),
|
|
}
|
|
|
|
// RunOrganizationList list user organizations
|
|
func RunOrganizationList(_ stdctx.Context, cmd *cli.Command) error {
|
|
ctx := context.InitCommand(cmd)
|
|
client := ctx.Login.Client()
|
|
|
|
userOrganizations, _, err := client.ListUserOrgs(ctx.Login.User, gitea.ListOrgsOptions{
|
|
ListOptions: ctx.GetListOptions(),
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
print.OrganizationsList(userOrganizations, ctx.Output)
|
|
|
|
return nil
|
|
}
|