mirror of
https://gitea.com/gitea/tea.git
synced 2024-12-26 02:49:45 +01:00
tea organizations list command (#264)
Introduce tea organizations list command (#263) Fix #263 Add missing pagination options missing as suggest by reviewers. (#263) Signed-off-by: Karl Heinz Marbaise <kama@soebes.de> Co-authored-by: Karl Heinz Marbaise <kama@soebes.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/264 Reviewed-by: Norwin <noerw@noreply.gitea.io> Reviewed-by: 6543 <6543@obermui.de> Co-Authored-By: khmarbaise <khmarbaise@noreply.gitea.io> Co-Committed-By: khmarbaise <khmarbaise@noreply.gitea.io>
This commit is contained in:
parent
4cb7d21a8f
commit
7d486c2ec6
@ -53,6 +53,8 @@ times Operate on tracked times of a repositorys issues and pulls
|
||||
open Open something of the repository on web browser
|
||||
notifications Show notifications
|
||||
milestones List and create milestones
|
||||
organizations List, create, delete organizations
|
||||
help, h Shows a list of commands or help for one command
|
||||
```
|
||||
|
||||
To fetch issues from different repos, use the `--remote` flag (when inside a gitea repository directory) or `--login` & `--repo` flags.
|
||||
|
39
cmd/organizations.go
Normal file
39
cmd/organizations.go
Normal file
@ -0,0 +1,39 @@
|
||||
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"code.gitea.io/tea/cmd/organizations"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// CmdOrgs represents handle organization
|
||||
var CmdOrgs = cli.Command{
|
||||
Name: "organizations",
|
||||
Aliases: []string{"organization", "org"},
|
||||
Usage: "List, create, delete organizations",
|
||||
Description: "Show organization details",
|
||||
ArgsUsage: "[<organization>]",
|
||||
Action: runOrganizations,
|
||||
Subcommands: []*cli.Command{
|
||||
&organizations.CmdOrganizationList,
|
||||
},
|
||||
}
|
||||
|
||||
func runOrganizations(ctx *cli.Context) error {
|
||||
if ctx.Args().Len() == 1 {
|
||||
return runOrganizationDetail(ctx.Args().First())
|
||||
}
|
||||
return organizations.RunOrganizationList(ctx)
|
||||
}
|
||||
|
||||
func runOrganizationDetail(path string) error {
|
||||
|
||||
log.Fatal("Not yet implemented.")
|
||||
return nil
|
||||
}
|
46
cmd/organizations/list.go
Normal file
46
cmd/organizations/list.go
Normal file
@ -0,0 +1,46 @@
|
||||
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package organizations
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// CmdOrganizationList represents a sub command of organizations to list users organizations
|
||||
var CmdOrganizationList = cli.Command{
|
||||
Name: "ls",
|
||||
Aliases: []string{"list"},
|
||||
Usage: "List Organizations",
|
||||
Description: "List users organizations",
|
||||
Action: RunOrganizationList,
|
||||
Flags: append([]cli.Flag{
|
||||
&flags.PaginationPageFlag,
|
||||
&flags.PaginationLimitFlag,
|
||||
}, flags.AllDefaultFlags...),
|
||||
}
|
||||
|
||||
// RunOrganizationList list user organizations
|
||||
func RunOrganizationList(ctx *cli.Context) error {
|
||||
//TODO: Reconsider the usage InitCommandLoginOnly related to #200
|
||||
login := config.InitCommandLoginOnly(flags.GlobalLoginValue)
|
||||
|
||||
client := login.Client()
|
||||
|
||||
userOrganizations, _, err := client.ListUserOrgs(login.User, gitea.ListOrgsOptions{ListOptions: flags.GetListOptions(ctx)})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
print.OrganizationsList(userOrganizations)
|
||||
|
||||
return nil
|
||||
}
|
1
main.go
1
main.go
@ -39,6 +39,7 @@ func main() {
|
||||
&cmd.CmdOpen,
|
||||
&cmd.CmdNotifications,
|
||||
&cmd.CmdMilestones,
|
||||
&cmd.CmdOrgs,
|
||||
}
|
||||
app.EnableBashCompletion = true
|
||||
err := app.Run(os.Args)
|
||||
|
45
modules/print/organization.go
Normal file
45
modules/print/organization.go
Normal file
@ -0,0 +1,45 @@
|
||||
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package print
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
)
|
||||
|
||||
// OrganizationsList prints a listing of the organizations
|
||||
func OrganizationsList(organizations []*gitea.Organization) {
|
||||
if len(organizations) == 0 {
|
||||
fmt.Println("No organizations found")
|
||||
return
|
||||
}
|
||||
|
||||
headers := []string{
|
||||
"Name",
|
||||
"FullName",
|
||||
"Website",
|
||||
"Location",
|
||||
"Description",
|
||||
}
|
||||
|
||||
var values [][]string
|
||||
|
||||
for _, org := range organizations {
|
||||
values = append(
|
||||
values,
|
||||
[]string{
|
||||
org.UserName,
|
||||
org.FullName,
|
||||
org.Website,
|
||||
org.Location,
|
||||
org.Description,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
OutputList(flags.GlobalOutputValue, headers, values)
|
||||
}
|
Loading…
Reference in New Issue
Block a user