mirror of
https://codeberg.org/forgejo/forgejo
synced 2025-10-18 22:50:36 +02:00
Fixes #9433. ``` $ ./gitea admin user create --username blah --must-change-password false Hint: boolean false must be specified as a single arg, eg. '--restricted=false', not '--restricted false' Command error: unexpected arguments: false ``` **Breaking**: CLI sub-commands that only have flags would previously ignore anything that might be considered an "extra" argument, and would proceed without any errors. I've manually tested this change on the single `admin user create` command with positive (ensuring cmd still works) and negative (ensuring errors are reported) test cases. I've attempted to ensure the change is applied only to commands which don't use the CLI `Args()` and avoided touching them, including: - `admin user must-change-password` takes a list of users - `doctor recreate-tables` takes a list of tables - `embedded [list/view/extract]` use a pattern of resources to operate upon - git repo hook subcommands, and the ssh serv command, use arguments and have been omitted from the change ## Checklist The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org). ### Tests - I added test coverage for Go changes... - [ ] in their respective `*_test.go` for unit tests. - [ ] in the `tests/integration` directory if it involves interactions with a live Forgejo server. - I added test coverage for JavaScript changes... - [ ] in `web_src/js/*.test.js` if it can be unit tested. - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)). ### Documentation - [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [x] I did not document these changes and I do not expect someone else to do it. ### Release notes - [ ] I do not want this change to show in the release notes. - [ ] I want the title to show in the release notes with a link to this pull request. - [x] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9458 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net> Co-committed-by: Mathieu Fenniak <mathieu@fenniak.net>
73 lines
1.8 KiB
Go
73 lines
1.8 KiB
Go
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"forgejo.org/modules/private"
|
|
"forgejo.org/modules/setting"
|
|
|
|
"github.com/urfave/cli/v3"
|
|
)
|
|
|
|
// CmdRestoreRepository represents the available restore a repository sub-command.
|
|
func cmdRestoreRepository() *cli.Command {
|
|
return &cli.Command{
|
|
Name: "restore-repo",
|
|
Usage: "Restore the repository from disk",
|
|
Description: "This is a command for restoring the repository data.",
|
|
Before: noDanglingArgs,
|
|
Action: runRestoreRepository,
|
|
Flags: []cli.Flag{
|
|
&cli.StringFlag{
|
|
Name: "repo_dir",
|
|
Aliases: []string{"r"},
|
|
Value: "./data",
|
|
Usage: "Repository dir path to restore from",
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "owner_name",
|
|
Value: "",
|
|
Usage: "Restore destination owner name",
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "repo_name",
|
|
Value: "",
|
|
Usage: "Restore destination repository name",
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "units",
|
|
Value: "",
|
|
Usage: `Which items will be restored, one or more units should be separated as comma.
|
|
wiki, issues, labels, releases, release_assets, milestones, pull_requests, comments are allowed. Empty means all units.`,
|
|
},
|
|
&cli.BoolFlag{
|
|
Name: "validation",
|
|
Usage: "Sanity check the content of the files before trying to load them",
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func runRestoreRepository(ctx context.Context, c *cli.Command) error {
|
|
ctx, cancel := installSignals(ctx)
|
|
defer cancel()
|
|
|
|
setting.MustInstalled()
|
|
var units []string
|
|
if s := c.String("units"); s != "" {
|
|
units = strings.Split(s, ",")
|
|
}
|
|
extra := private.RestoreRepo(
|
|
ctx,
|
|
c.String("repo_dir"),
|
|
c.String("owner_name"),
|
|
c.String("repo_name"),
|
|
units,
|
|
c.Bool("validation"),
|
|
)
|
|
return handleCliResponseExtra(extra)
|
|
}
|