7174fd0007
Universal: PR Check / Branch Policy (pull_request) Successful in 2s
Universal: PR Check / Validate PR (pull_request) Successful in 10s
Generic: Project CI / Lint & Validate (pull_request) Successful in 35s
Generic: Standards Compliance / Secret Scanning (push) Failing after 11s
Generic: Standards Compliance / License Header Validation (push) Successful in 9s
Generic: Standards Compliance / Repository Structure Validation (push) Successful in 10s
Generic: Standards Compliance / Coding Standards Check (push) Successful in 13s
Universal: PR Check / Secret Scan (pull_request) Successful in 1m36s
Deploy (Prod) / Build & Deploy to Prod (push) Failing after 1m27s
Generic: Standards Compliance / Workflow Configuration Check (push) Failing after 11s
Generic: Standards Compliance / Documentation Quality Check (push) Successful in 10s
Generic: Standards Compliance / README Completeness Check (push) Failing after 10s
Generic: Standards Compliance / Script Integrity Validation (push) Successful in 11s
Generic: Standards Compliance / Line Length Check (push) Successful in 22s
Generic: Standards Compliance / Version Consistency Check (push) Successful in 1m15s
Generic: Standards Compliance / File Naming Standards (push) Successful in 10s
Generic: Standards Compliance / Insecure Code Pattern Detection (push) Successful in 10s
Generic: Standards Compliance / Git Repository Hygiene (push) Successful in 1m20s
Generic: Standards Compliance / Dead Code Detection (push) Successful in 13s
Generic: Standards Compliance / File Size Limits (push) Successful in 10s
Generic: Standards Compliance / Code Complexity Analysis (push) Successful in 1m12s
Generic: Standards Compliance / TODO/FIXME Tracking (push) Successful in 9s
Generic: Standards Compliance / Code Duplication Detection (push) Successful in 2m25s
Generic: Standards Compliance / Binary File Detection (push) Successful in 1m58s
Generic: Standards Compliance / Broken Link Detection (push) Successful in 13s
Generic: Standards Compliance / Dependency Vulnerability Scanning (push) Successful in 1m47s
Generic: Standards Compliance / API Documentation Coverage (push) Successful in 10s
Generic: Standards Compliance / Accessibility Check (push) Successful in 11s
Generic: Standards Compliance / Performance Metrics (push) Successful in 11s
Generic: Standards Compliance / Unused Dependencies Check (push) Successful in 1m17s
Generic: Standards Compliance / Terraform Configuration Validation (push) Successful in 18s
Generic: Standards Compliance / Enterprise Readiness Check (push) Successful in 1m4s
Generic: Standards Compliance / Repository Health Check (push) Successful in 1m2s
Generic: Project CI / Tests (pull_request) Has been cancelled
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
Universal: PR Check / Report Issues (pull_request) Has been cancelled
Generic: Standards Compliance / Compliance Summary (push) Has been cancelled
The CLI app name (cmd/main.go app.Name) was still 'gitea', so `mokogit --version` and the USAGE/help printed 'gitea version X' and 'gitea doctor ...'. Rename it to 'mokogit' (lower-cased per the USAGE convention) and rebrand the two adjacent Gitea CLI strings (program description, --work-path usage). Verified: go build ./cmd/. Does NOT rename the executable file (still /app/gitea/gitea); that touches Dockerfile/systemd/deploy paths and is a separate, larger change.
173 lines
4.9 KiB
Go
173 lines
4.9 KiB
Go
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"strings"
|
|
|
|
"code.mokoconsulting.tech/MokoConsulting/MokoGIT/modules/log"
|
|
"code.mokoconsulting.tech/MokoConsulting/MokoGIT/modules/setting"
|
|
|
|
"github.com/urfave/cli/v3"
|
|
)
|
|
|
|
var cliHelpPrinterOld = cli.HelpPrinter
|
|
|
|
func init() {
|
|
cli.HelpPrinter = cliHelpPrinterNew
|
|
}
|
|
|
|
// cliHelpPrinterNew helps to print "DEFAULT CONFIGURATION" for the following cases ( "-c" can apper in any position):
|
|
// * ./gitea -c /dev/null -h
|
|
// * ./gitea -c help /dev/null help
|
|
// * ./gitea help -c /dev/null
|
|
// * ./gitea help -c /dev/null web
|
|
// * ./gitea help web -c /dev/null
|
|
// * ./gitea web help -c /dev/null
|
|
// * ./gitea web -h -c /dev/null
|
|
func cliHelpPrinterNew(out io.Writer, templ string, data any) {
|
|
cmd, _ := data.(*cli.Command)
|
|
if cmd != nil {
|
|
prepareWorkPathAndCustomConf(cmd)
|
|
}
|
|
cliHelpPrinterOld(out, templ, data)
|
|
if setting.CustomConf != "" {
|
|
_, _ = fmt.Fprintf(out, `
|
|
DEFAULT CONFIGURATION:
|
|
AppPath: %s
|
|
WorkPath: %s
|
|
CustomPath: %s
|
|
ConfigFile: %s
|
|
|
|
`, setting.AppPath, setting.AppWorkPath, setting.CustomPath, setting.CustomConf)
|
|
}
|
|
}
|
|
|
|
func PrepareSubcommandWithGlobalFlags(originCmd *cli.Command) {
|
|
originBefore := originCmd.Before
|
|
originCmd.Before = func(ctxOrig context.Context, cmd *cli.Command) (ctx context.Context, err error) {
|
|
ctx = ctxOrig
|
|
if originBefore != nil {
|
|
ctx, err = originBefore(ctx, cmd)
|
|
if err != nil {
|
|
return ctx, err
|
|
}
|
|
}
|
|
prepareWorkPathAndCustomConf(cmd)
|
|
return ctx, nil
|
|
}
|
|
}
|
|
|
|
// prepareWorkPathAndCustomConf tries to prepare the work path, custom path and custom config from various inputs:
|
|
// command line flags, environment variables, config file
|
|
func prepareWorkPathAndCustomConf(cmd *cli.Command) {
|
|
var args setting.ArgWorkPathAndCustomConf
|
|
if cmd.IsSet("work-path") {
|
|
args.WorkPath = cmd.String("work-path")
|
|
}
|
|
if cmd.IsSet("custom-path") {
|
|
args.CustomPath = cmd.String("custom-path")
|
|
}
|
|
if cmd.IsSet("config") {
|
|
args.CustomConf = cmd.String("config")
|
|
}
|
|
setting.InitWorkPathAndCommonConfig(os.Getenv, args)
|
|
}
|
|
|
|
type AppVersion struct {
|
|
Version string
|
|
Extra string
|
|
}
|
|
|
|
func NewMainApp(appVer AppVersion) *cli.Command {
|
|
app := &cli.Command{}
|
|
app.Name = "mokogit" // must be lower-cased because it appears in the "USAGE" section like "mokogit doctor [command [command options]]" and in `mokogit --version`
|
|
app.Usage = "A painless self-hosted Git service"
|
|
app.Description = `MokoGIT program contains "web" and other subcommands. If no subcommand is given, it starts the web server by default. Use "web" subcommand for more web server arguments, use other subcommands for other purposes.`
|
|
app.Version = appVer.Version + appVer.Extra
|
|
app.EnableShellCompletion = true
|
|
app.Flags = []cli.Flag{
|
|
&cli.StringFlag{
|
|
Name: "work-path",
|
|
Aliases: []string{"w"},
|
|
TakesFile: true,
|
|
Usage: "Set MokoGIT's working path (defaults to the MokoGIT's binary directory)",
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "config",
|
|
Aliases: []string{"c"},
|
|
TakesFile: true,
|
|
Value: setting.CustomConf,
|
|
Usage: "Set custom config file (defaults to '{WorkPath}/custom/conf/app.ini')",
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "custom-path",
|
|
Aliases: []string{"C"},
|
|
TakesFile: true,
|
|
Usage: "Set custom path (defaults to '{WorkPath}/custom')",
|
|
},
|
|
}
|
|
webCmd := newWebCommand()
|
|
// these sub-commands need to use a config file
|
|
subCmdWithConfig := []*cli.Command{
|
|
webCmd,
|
|
newServCommand(),
|
|
newHookCommand(),
|
|
NewKeysCommand(),
|
|
newDumpCommand(),
|
|
newAdminCommand(),
|
|
newMigrateCommand(),
|
|
newDoctorCommand(),
|
|
newManagerCommand(),
|
|
newEmbeddedCommand(),
|
|
newMigrateStorageCommand(),
|
|
newDumpRepositoryCommand(),
|
|
newRestoreRepositoryCommand(),
|
|
newActionsCommand(),
|
|
}
|
|
|
|
// these sub-commands do not need the config file, and they do not depend on any path or environment variable.
|
|
subCmdStandalone := []*cli.Command{
|
|
cmdConfig(),
|
|
cmdCert(),
|
|
newGenerateCommand(),
|
|
newDocsCommand(),
|
|
}
|
|
|
|
// TODO: we should eventually drop the default command,
|
|
// but not sure whether it would break Windows users who used to double-click the EXE to run.
|
|
app.DefaultCommand = webCmd.Name
|
|
|
|
app.Before = PrepareConsoleLoggerLevel(log.INFO)
|
|
for i := range subCmdWithConfig {
|
|
PrepareSubcommandWithGlobalFlags(subCmdWithConfig[i])
|
|
}
|
|
app.Commands = append(app.Commands, subCmdWithConfig...)
|
|
app.Commands = append(app.Commands, subCmdStandalone...)
|
|
|
|
setting.UnsetUnnecessaryEnvVars()
|
|
return app
|
|
}
|
|
|
|
func RunMainApp(app *cli.Command, args ...string) error {
|
|
ctx, cancel := installSignals()
|
|
defer cancel()
|
|
err := app.Run(ctx, args)
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
if strings.HasPrefix(err.Error(), "flag provided but not defined:") {
|
|
// the cli package should already have output the error message, so just exit
|
|
cli.OsExiter(1)
|
|
return err
|
|
}
|
|
_, _ = fmt.Fprintf(app.ErrWriter, "Command error: %v\n", err)
|
|
cli.OsExiter(1)
|
|
return err
|
|
}
|