mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-25 14:55:40 +03:00
[CLI] implement forgejo-cli (squash) support initDB
This commit is contained in:
parent
8756c9a72a
commit
5c31ae602a
2 changed files with 27 additions and 6 deletions
|
@ -11,7 +11,10 @@ import (
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/models/db"
|
||||||
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/private"
|
"code.gitea.io/gitea/modules/private"
|
||||||
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
@ -19,7 +22,7 @@ import (
|
||||||
type key int
|
type key int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
noInstallSignalsKey key = iota + 1
|
noInitKey key = iota + 1
|
||||||
noExitKey
|
noExitKey
|
||||||
stdoutKey
|
stdoutKey
|
||||||
stderrKey
|
stderrKey
|
||||||
|
@ -37,12 +40,12 @@ func CmdForgejo(ctx context.Context) cli.Command {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ContextSetNoInstallSignals(ctx context.Context, value bool) context.Context {
|
func ContextSetNoInit(ctx context.Context, value bool) context.Context {
|
||||||
return context.WithValue(ctx, noInstallSignalsKey, value)
|
return context.WithValue(ctx, noInitKey, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ContextGetNoInstallSignals(ctx context.Context) bool {
|
func ContextGetNoInit(ctx context.Context) bool {
|
||||||
value, ok := ctx.Value(noInstallSignalsKey).(bool)
|
value, ok := ctx.Value(noInitKey).(bool)
|
||||||
return ok && value
|
return ok && value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,6 +94,24 @@ func ContextGetStdin(ctx context.Context) io.Reader {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// copied from ../cmd.go
|
||||||
|
func initDB(ctx context.Context) error {
|
||||||
|
setting.MustInstalled()
|
||||||
|
setting.LoadDBSetting()
|
||||||
|
setting.InitSQLLoggersForCli(log.INFO)
|
||||||
|
|
||||||
|
if setting.Database.Type == "" {
|
||||||
|
log.Fatal(`Database settings are missing from the configuration file: %q.
|
||||||
|
Ensure you are running in the correct environment or set the correct configuration file with -c.
|
||||||
|
If this is the intended configuration file complete the [database] section.`, setting.CustomConf)
|
||||||
|
}
|
||||||
|
if err := db.InitEngine(ctx); err != nil {
|
||||||
|
return fmt.Errorf("unable to initialize the database using the configuration in %q. Error: %w", setting.CustomConf, err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// copied from ../cmd.go
|
||||||
func installSignals(ctx context.Context) (context.Context, context.CancelFunc) {
|
func installSignals(ctx context.Context) (context.Context, context.CancelFunc) {
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
go func() {
|
go func() {
|
||||||
|
|
|
@ -24,7 +24,7 @@ func cmdForgejoCaptureOutput(t *testing.T, args []string, stdin ...string) (stri
|
||||||
assert.NoError(t, set.Parse(args))
|
assert.NoError(t, set.Parse(args))
|
||||||
cliContext := cli.NewContext(&cli.App{Writer: w, ErrWriter: w}, set, nil)
|
cliContext := cli.NewContext(&cli.App{Writer: w, ErrWriter: w}, set, nil)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
ctx = forgejo.ContextSetNoInstallSignals(ctx, true)
|
ctx = forgejo.ContextSetNoInit(ctx, true)
|
||||||
ctx = forgejo.ContextSetNoExit(ctx, true)
|
ctx = forgejo.ContextSetNoExit(ctx, true)
|
||||||
ctx = forgejo.ContextSetStdout(ctx, w)
|
ctx = forgejo.ContextSetStdout(ctx, w)
|
||||||
ctx = forgejo.ContextSetStderr(ctx, w)
|
ctx = forgejo.ContextSetStderr(ctx, w)
|
||||||
|
|
Loading…
Reference in a new issue