[CLI] implement forgejo-cli actions (squash) restore --version
Refs: https://codeberg.org/forgejo/forgejo/issues/1134
This commit is contained in:
parent
7e097b945c
commit
e2000f5bfc
4 changed files with 30 additions and 27 deletions
24
cmd/main.go
24
cmd/main.go
|
@ -61,8 +61,7 @@ func appGlobalFlags() []cli.Flag {
|
|||
return []cli.Flag{
|
||||
// make the builtin flags at the top
|
||||
helpFlag,
|
||||
// Forgejo: commented out because it would conflict at runtime with the --version
|
||||
// cli.VersionFlag,
|
||||
cli.VersionFlag,
|
||||
|
||||
// shared configuration flags, they are for global and for each sub-command at the same time
|
||||
// eg: such command is valid: "./gitea --config /tmp/app.ini web --config /tmp/app.ini", while it's discouraged indeed
|
||||
|
@ -86,25 +85,6 @@ func appGlobalFlags() []cli.Flag {
|
|||
}
|
||||
}
|
||||
|
||||
func makePathOutput(workPath, customPath, customConf string) string {
|
||||
return fmt.Sprintf("WorkPath=%s\nCustomPath=%s\nCustomConf=%s", workPath, customPath, customConf)
|
||||
}
|
||||
|
||||
func NewTestApp() *cli.App {
|
||||
app := NewMainApp()
|
||||
testCmd := &cli.Command{
|
||||
Name: "test-cmd",
|
||||
Action: func(ctx *cli.Context) error {
|
||||
_, _ = fmt.Fprint(app.Writer, makePathOutput(setting.AppWorkPath, setting.CustomPath, setting.CustomConf))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
prepareSubcommandWithConfig(testCmd, appGlobalFlags())
|
||||
app.Commands = append(app.Commands, testCmd)
|
||||
app.DefaultCommand = testCmd.Name
|
||||
return app
|
||||
}
|
||||
|
||||
func prepareSubcommandWithConfig(command *cli.Command, globalFlags []cli.Flag) {
|
||||
command.Flags = append(append([]cli.Flag{}, globalFlags...), command.Flags...)
|
||||
command.Action = prepareWorkPathAndCustomConf(command.Action)
|
||||
|
@ -231,7 +211,6 @@ func newMainApp(subCmds ...*cli.Command) *cli.App {
|
|||
cmdConvert := util.ToPointer(*cmdDoctorConvert)
|
||||
cmdConvert.Hidden = true // still support the legacy "./gitea doctor" by the hidden sub-command, remove it in next release
|
||||
subCmdWithConfig = append(subCmdWithConfig, cmdConvert)
|
||||
subCmdWithConfig = append(subCmdWithConfig, subCmds...)
|
||||
|
||||
// these sub-commands do not need the config file, and they do not depend on any path or environment variable.
|
||||
subCmdStandalone := []*cli.Command{
|
||||
|
@ -251,6 +230,7 @@ func newMainApp(subCmds ...*cli.Command) *cli.App {
|
|||
}
|
||||
app.Commands = append(app.Commands, subCmdWithConfig...)
|
||||
app.Commands = append(app.Commands, subCmdStandalone...)
|
||||
app.Commands = append(app.Commands, subCmds...)
|
||||
|
||||
if !checkCommandFlags(app) {
|
||||
panic("some flags are incorrect") // this is a runtime check to help developers
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue