Added commands for urfave/cli.
This commit is contained in:
parent
98353c6ae2
commit
6474c45abb
3 changed files with 103 additions and 0 deletions
36
internal/commands/common.go
Normal file
36
internal/commands/common.go
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"code.destrealm.net/zancarius/justusbot/internal/settings"
|
||||
"go.destrealm.net/vfs"
|
||||
)
|
||||
|
||||
type commands struct {
|
||||
root vfs.VFS
|
||||
meta *metadata
|
||||
settings *settings.Settings
|
||||
}
|
||||
|
||||
func NewCommandHost(root vfs.VFS) (*commands, error) {
|
||||
conf, err := settings.LoadSettings("settings.toml", root)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cmd := &commands{
|
||||
root: root,
|
||||
settings: conf,
|
||||
}
|
||||
cmd.meta = OpenMetadata(root, cmd)
|
||||
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
func (c *commands) Initalizer() *installer {
|
||||
i, _ := initInstaller(c.root, c.settings)
|
||||
return i
|
||||
}
|
||||
|
||||
func (c *commands) Meta() *metadata {
|
||||
return c.meta
|
||||
}
|
||||
29
internal/commands/dump.go
Normal file
29
internal/commands/dump.go
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"code.destrealm.net/zancarius/justusbot/internal/settings"
|
||||
"github.com/urfave/cli/v3"
|
||||
"go.destrealm.net/vfs"
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
fs vfs.VFS
|
||||
settings *settings.Settings
|
||||
}
|
||||
|
||||
func OpenMetadata(fs vfs.VFS, host *commands) *metadata {
|
||||
tfs := fs.Clone()
|
||||
tfs.Chroot("./data/translations")
|
||||
return &metadata{tfs, host.settings}
|
||||
}
|
||||
|
||||
func (m *metadata) DumpStructure(ctx context.Context, cmd *cli.Command) error {
|
||||
format := cmd.String("format")
|
||||
_ = format
|
||||
|
||||
fmt.Println("dump")
|
||||
return nil
|
||||
}
|
||||
38
internal/commands/install.go
Normal file
38
internal/commands/install.go
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"code.destrealm.net/zancarius/justusbot/internal/models"
|
||||
"code.destrealm.net/zancarius/justusbot/internal/settings"
|
||||
"github.com/urfave/cli/v3"
|
||||
"go.destrealm.net/errors"
|
||||
"go.destrealm.net/logging/v3"
|
||||
"go.destrealm.net/vfs"
|
||||
)
|
||||
|
||||
type installer struct {
|
||||
fs vfs.VFS
|
||||
logger *logging.Log
|
||||
settings *settings.Settings
|
||||
}
|
||||
|
||||
func initInstaller(fs vfs.VFS, settings *settings.Settings) (*installer, error) {
|
||||
return &installer{
|
||||
fs,
|
||||
logging.Get("initializer"),
|
||||
settings,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (inst *installer) DoInstall(ctx context.Context, cmd *cli.Command) error {
|
||||
fmt.Println(inst.settings)
|
||||
db := models.CreateDatabase(inst.settings)
|
||||
fmt.Println(inst.settings.System.DSN)
|
||||
err := db.Migrate(inst.fs)
|
||||
if err != nil {
|
||||
inst.logger.Error(errors.Unfurl(err))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Loading…
Reference in a new issue