tea organizations list command #264
|
@ -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...),
|
||||
}
|
||||
|
||||
noerw marked this conversation as resolved
Outdated
noerw
commented
Note for later (no need to adress this in this PR): Note for later (no need to adress this in this PR):
By using `InitCommandLoginOnly()` repo-based login detection fails, see #200
|
||||
// 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 {
|
||||
noerw marked this conversation as resolved
Outdated
khmarbaise
commented
Here I'm not sure which exact user information should be used Here I'm not sure which exact user information should be used `info.UserName` makes it working. where is the difference to `long.Name` ?
noerw
commented
`login.Name` is the ID of tea specific configuration for each gitea instance.
`login.User` holds the user name that the auth token belongs to, so you can skip the call to `GetMyUserInfo()`
|
||||
log.Fatal(err)
|
||||
6543 marked this conversation as resolved
Outdated
6543
commented
can you move list printing func into like it's done with list repos: https://gitea.com/gitea/tea/src/branch/master/cmd/repos/list.go#L83 yes list issues do not do it now - need a refactor ... can you move list printing func into `modules/print`
like it's done with list repos:
https://gitea.com/gitea/tea/src/branch/master/cmd/repos/list.go#L83
https://gitea.com/gitea/tea/src/branch/master/modules/print/repo.go#L63
yes list issues do not do it now - need a refactor ...
khmarbaise
commented
Changed as requested. Changed as requested.
|
||||
}
|
||||
|
||||
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
paggination options missing
example:
Changes as suggested. Thanks for the hints.