mirror of
https://github.com/m1k1o/neko.git
synced 2025-05-23 05:57:11 +02:00
post megre cleanup.
This commit is contained in:
parent
3e1def9041
commit
5b96fd5f5e
284 changed files with 7103 additions and 11307 deletions
49
server/cmd/plugins.go
Normal file
49
server/cmd/plugins.go
Normal file
|
@ -0,0 +1,49 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
|
||||
"github.com/demodesk/neko/internal/config"
|
||||
"github.com/demodesk/neko/internal/plugins"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func init() {
|
||||
command := &cobra.Command{
|
||||
Use: "plugins [directory]",
|
||||
Short: "load, verify and list plugins",
|
||||
Long: `load, verify and list plugins`,
|
||||
Run: pluginsCmd,
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
}
|
||||
root.AddCommand(command)
|
||||
}
|
||||
|
||||
func pluginsCmd(cmd *cobra.Command, args []string) {
|
||||
pluginDir := "/etc/neko/plugins"
|
||||
if len(args) > 0 {
|
||||
pluginDir = args[0]
|
||||
}
|
||||
log.Info().Str("dir", pluginDir).Msg("plugins directory")
|
||||
|
||||
plugs := plugins.New(&config.Plugins{
|
||||
Enabled: true,
|
||||
Required: true,
|
||||
Dir: pluginDir,
|
||||
})
|
||||
|
||||
meta := plugs.Metadata()
|
||||
if len(meta) == 0 {
|
||||
log.Fatal().Msg("no plugins found")
|
||||
}
|
||||
|
||||
// marshal indent to stdout
|
||||
dec := json.NewEncoder(os.Stdout)
|
||||
dec.SetIndent("", " ")
|
||||
err := dec.Encode(meta)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("unable to marshal metadata")
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue