gitlink-cli/shortcuts/org/org.go

165 lines
4.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package org
import (
"fmt"
"net/url"
"github.com/gitlink-org/gitlink-cli/shortcuts/common"
)
func Shortcuts() []*common.Shortcut {
return []*common.Shortcut{
// +list列出组织
{
Name: "list",
Description: "列出组织",
Long: `List all organizations visible to the authenticated user.
Returns organization ID, name, and description for each entry.
Use --page and --limit for pagination.`,
Example: ` # List organizations
gitlink org +list
# Show 50 organizations per page
gitlink org +list --limit 50`,
Flags: []common.Flag{
{Name: "page", Short: "p", Usage: "Page number", Default: "1"},
{Name: "limit", Short: "l", Usage: "Items per page", Default: "20"},
},
Run: func(ctx *common.RuntimeContext) error {
q := url.Values{}
q.Set("page", ctx.Arg("page"))
q.Set("limit", ctx.Arg("limit"))
env, err := ctx.CallAPIWithQuery("GET", "/organizations", q)
if err != nil {
return err
}
return ctx.Output(env)
},
},
// +info查看组织详情
{
Name: "info",
Description: "查看组织详情",
Long: `Show detailed information about an organization.
Returns the full organization profile including name, description,
member count, and repository list.`,
Example: ` # Show details for an organization by ID
gitlink org +info --id 123
# Show details for an organization by login
gitlink org +info --id my-org`,
Flags: []common.Flag{
{Name: "id", Short: "i", Usage: "Organization ID or login", Required: true},
},
Run: func(ctx *common.RuntimeContext) error {
id, _ := ctx.RequireArg("id")
env, err := ctx.CallAPI("GET", fmt.Sprintf("/organizations/%s", id), nil)
if err != nil {
return err
}
return ctx.Output(env)
},
},
// +members列出组织成员
{
Name: "members",
Description: "列出组织成员",
Long: `List all members of an organization.
Shows each member's login name, role, and join date.
Use --page and --limit for pagination.`,
Example: ` # List members of an organization
gitlink org +members --id 123
# Show 50 members per page
gitlink org +members --id 123 --limit 50`,
Flags: []common.Flag{
{Name: "id", Short: "i", Usage: "Organization ID", Required: true},
{Name: "page", Short: "p", Usage: "Page number", Default: "1"},
{Name: "limit", Short: "l", Usage: "Items per page", Default: "20"},
},
Run: func(ctx *common.RuntimeContext) error {
id, _ := ctx.RequireArg("id")
q := url.Values{}
q.Set("page", ctx.Arg("page"))
q.Set("limit", ctx.Arg("limit"))
env, err := ctx.CallAPIWithQuery("GET", fmt.Sprintf("/organizations/%s/organization_users", id), q)
if err != nil {
return err
}
return ctx.Output(env)
},
},
// +create创建组织
{
Name: "create",
Description: "创建组织",
Long: `Create a new organization on GitLink.
Requires a name for the organization. An optional description
can be provided with --description.`,
Example: ` # Create an organization
gitlink org +create --name my-org
# Create with a description
gitlink org +create --name my-org --description "My team organization"`,
Flags: []common.Flag{
{Name: "name", Short: "n", Usage: "Organization name", Required: true},
{Name: "description", Short: "d", Usage: "Description"},
},
Run: func(ctx *common.RuntimeContext) error {
name, _ := ctx.RequireArg("name")
payload := map[string]interface{}{
"name": name,
}
if d := ctx.Arg("description"); d != "" {
payload["description"] = d
}
env, err := ctx.CallAPI("POST", "/organizations", payload)
if err != nil {
return err
}
return ctx.Output(env)
},
},
// +add-team-projects为团队添加全部项目
{
Name: "add-team-projects",
Description: "为团队添加全部项目",
Flags: []common.Flag{
{Name: "org", Short: "o", Usage: "Organization login", Required: true},
{Name: "team", Short: "t", Usage: "Team ID", Required: true},
},
Run: func(ctx *common.RuntimeContext) error {
org, _ := ctx.RequireArg("org")
team, _ := ctx.RequireArg("team")
env, err := ctx.CallAPI("POST", fmt.Sprintf("/organizations/%s/teams/%s/team_projects/create_all", org, team), nil)
if err != nil {
return err
}
return ctx.Output(env)
},
},
// +remove-team-projects移除团队的全部项目
{
Name: "remove-team-projects",
Description: "移除团队的全部项目",
Flags: []common.Flag{
{Name: "org", Short: "o", Usage: "Organization login", Required: true},
{Name: "team", Short: "t", Usage: "Team ID", Required: true},
},
Run: func(ctx *common.RuntimeContext) error {
org, _ := ctx.RequireArg("org")
team, _ := ctx.RequireArg("team")
env, err := ctx.CallAPI("DELETE", fmt.Sprintf("/organizations/%s/teams/%s/team_projects/destroy_all", org, team), nil)
if err != nil {
return err
}
return ctx.Output(env)
},
},
}
}