Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions cmd/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ import (
"github.com/urfave/cli/v3"
)

var (
// CmdActions represents the available actions sub-commands.
CmdActions = &cli.Command{
func newActionsCommand() *cli.Command {
return &cli.Command{
Name: "actions",
Usage: "Manage Gitea Actions",
Commands: []*cli.Command{
subcmdActionsGenRunnerToken,
newActionsGenerateRunnerTokenCommand(),
},
}
}

subcmdActionsGenRunnerToken = &cli.Command{
func newActionsGenerateRunnerTokenCommand() *cli.Command {
return &cli.Command{
Name: "generate-runner-token",
Usage: "Generate a new token for a runner to use to register with the server",
Action: runGenerateActionsRunnerToken,
Expand All @@ -37,7 +38,7 @@ var (
},
},
}
)
}

func runGenerateActionsRunnerToken(ctx context.Context, c *cli.Command) error {
setting.MustInstalled()
Expand Down
41 changes: 24 additions & 17 deletions cmd/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,41 @@ import (
"github.com/urfave/cli/v3"
)

var (
// CmdAdmin represents the available admin sub-command.
CmdAdmin = &cli.Command{
func newAdminCommand() *cli.Command {
return &cli.Command{
Name: "admin",
Usage: "Perform common administrative operations",
Commands: []*cli.Command{
subcmdUser,
subcmdRepoSyncReleases,
subcmdRegenerate,
subcmdAuth,
subcmdSendMail,
newUserCommand(),
newRepoSyncReleasesCommand(),
newRegenerateCommand(),
newAuthCommand(),
newSendMailCommand(),
},
}
}

subcmdRepoSyncReleases = &cli.Command{
func newRepoSyncReleasesCommand() *cli.Command {
return &cli.Command{
Name: "repo-sync-releases",
Usage: "Synchronize repository releases with tags",
Action: runRepoSyncReleases,
}
}

subcmdRegenerate = &cli.Command{
func newRegenerateCommand() *cli.Command {
return &cli.Command{
Name: "regenerate",
Usage: "Regenerate specific files",
Commands: []*cli.Command{
microcmdRegenHooks,
microcmdRegenKeys,
newRegenerateHooksCommand(),
newRegenerateKeysCommand(),
},
}
}

subcmdAuth = &cli.Command{
func newAuthCommand() *cli.Command {
return &cli.Command{
Name: "auth",
Usage: "Modify external auth providers",
Commands: []*cli.Command{
Expand All @@ -59,12 +64,14 @@ var (
microcmdAuthUpdateLdapSimpleAuth(),
microcmdAuthAddSMTP(),
microcmdAuthUpdateSMTP(),
microcmdAuthList,
microcmdAuthDelete,
newAuthListCommand(),
newAuthDeleteCommand(),
},
}
}

subcmdSendMail = &cli.Command{
func newSendMailCommand() *cli.Command {
return &cli.Command{
Name: "sendmail",
Usage: "Send a message to all users",
Action: runSendMail,
Expand All @@ -86,7 +93,7 @@ var (
},
},
}
)
}

func idFlag() *cli.Int64Flag {
return &cli.Int64Flag{
Expand Down
11 changes: 7 additions & 4 deletions cmd/admin_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ import (
"github.com/urfave/cli/v3"
)

var (
microcmdAuthDelete = &cli.Command{
func newAuthDeleteCommand() *cli.Command {
return &cli.Command{
Name: "delete",
Usage: "Delete specific auth source",
Flags: []cli.Flag{idFlag()},
Action: runDeleteAuth,
}
microcmdAuthList = &cli.Command{
}

func newAuthListCommand() *cli.Command {
return &cli.Command{
Name: "list",
Usage: "List auth sources",
Action: runListAuth,
Expand Down Expand Up @@ -55,7 +58,7 @@ var (
},
},
}
)
}

func runListAuth(ctx context.Context, c *cli.Command) error {
if err := initDB(ctx); err != nil {
Expand Down
10 changes: 6 additions & 4 deletions cmd/admin_regenerate.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@ import (
"github.com/urfave/cli/v3"
)

var (
microcmdRegenHooks = &cli.Command{
func newRegenerateHooksCommand() *cli.Command {
return &cli.Command{
Name: "hooks",
Usage: "Regenerate git-hooks",
Action: runRegenerateHooks,
}
}

microcmdRegenKeys = &cli.Command{
func newRegenerateKeysCommand() *cli.Command {
return &cli.Command{
Name: "keys",
Usage: "Regenerate authorized_keys file",
Action: runRegenerateKeys,
}
)
}

func runRegenerateHooks(ctx context.Context, _ *cli.Command) error {
if err := initDB(ctx); err != nil {
Expand Down
24 changes: 13 additions & 11 deletions cmd/admin_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ import (
"github.com/urfave/cli/v3"
)

var subcmdUser = &cli.Command{
Name: "user",
Usage: "Modify users",
Commands: []*cli.Command{
microcmdUserCreate(),
microcmdUserList,
microcmdUserChangePassword(),
microcmdUserDelete(),
microcmdUserGenerateAccessToken,
microcmdUserMustChangePassword(),
},
func newUserCommand() *cli.Command {
return &cli.Command{
Name: "user",
Usage: "Modify users",
Commands: []*cli.Command{
microcmdUserCreate(),
newUserListCommand(),
microcmdUserChangePassword(),
microcmdUserDelete(),
newUserGenerateAccessTokenCommand(),
microcmdUserMustChangePassword(),
},
}
}
52 changes: 27 additions & 25 deletions cmd/admin_user_generate_access_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,34 @@ import (
"github.com/urfave/cli/v3"
)

var microcmdUserGenerateAccessToken = &cli.Command{
Name: "generate-access-token",
Usage: "Generate an access token for a specific user",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "username",
Aliases: []string{"u"},
Usage: "Username",
func newUserGenerateAccessTokenCommand() *cli.Command {
return &cli.Command{
Name: "generate-access-token",
Usage: "Generate an access token for a specific user",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "username",
Aliases: []string{"u"},
Usage: "Username",
},
&cli.StringFlag{
Name: "token-name",
Aliases: []string{"t"},
Usage: "Token name",
Value: "gitea-admin",
},
&cli.BoolFlag{
Name: "raw",
Usage: "Display only the token value",
},
&cli.StringFlag{
Name: "scopes",
Value: "all",
Usage: `Comma separated list of scopes to apply to access token, examples: "all", "public-only,read:issue", "write:repository,write:user"`,
},
},
&cli.StringFlag{
Name: "token-name",
Aliases: []string{"t"},
Usage: "Token name",
Value: "gitea-admin",
},
&cli.BoolFlag{
Name: "raw",
Usage: "Display only the token value",
},
&cli.StringFlag{
Name: "scopes",
Value: "all",
Usage: `Comma separated list of scopes to apply to access token, examples: "all", "public-only,read:issue", "write:repository,write:user"`,
},
},
Action: runGenerateAccessToken,
Action: runGenerateAccessToken,
}
}

func runGenerateAccessToken(ctx context.Context, c *cli.Command) error {
Expand Down
20 changes: 11 additions & 9 deletions cmd/admin_user_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ import (
"github.com/urfave/cli/v3"
)

var microcmdUserList = &cli.Command{
Name: "list",
Usage: "List users",
Action: runListUsers,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "admin",
Usage: "List only admin users",
func newUserListCommand() *cli.Command {
return &cli.Command{
Name: "list",
Usage: "List users",
Action: runListUsers,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "admin",
Usage: "List only admin users",
},
},
},
}
}

func runListUsers(ctx context.Context, c *cli.Command) error {
Expand Down
33 changes: 17 additions & 16 deletions cmd/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,24 @@ import (
"github.com/urfave/cli/v3"
)

// CmdDocs represents the available docs sub-command.
var CmdDocs = &cli.Command{
Name: "docs",
Usage: "Output CLI documentation",
Description: "A command to output Gitea's CLI documentation, optionally to a file.",
Action: runDocs,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "man",
Usage: "Output man pages instead",
func newDocsCommand() *cli.Command {
return &cli.Command{
Name: "docs",
Usage: "Output CLI documentation",
Description: "A command to output Gitea's CLI documentation, optionally to a file.",
Action: runDocs,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "man",
Usage: "Output man pages instead",
},
&cli.StringFlag{
Name: "output",
Aliases: []string{"o"},
Usage: "Path to output to instead of stdout (will overwrite if exists)",
},
},
&cli.StringFlag{
Name: "output",
Aliases: []string{"o"},
Usage: "Path to output to instead of stdout (will overwrite if exists)",
},
},
}
}

func runDocs(_ context.Context, cmd *cli.Command) error {
Expand Down
Loading