enable gitea actions

This commit is contained in:
Aleksandr Trushkin
2024-02-02 18:24:00 +03:00
parent 4ceeba1608
commit d18d1d44dd
9 changed files with 124 additions and 44 deletions

View File

@ -2,8 +2,10 @@ package components
import (
"context"
"errors"
"fmt"
"io"
"os"
"time"
"git.loyso.art/frx/eway/internal/config"
@ -40,6 +42,11 @@ func GetLogger() (zerolog.Logger, error) {
func SetupDI(ctx context.Context, cfgpath string) error {
cfg, err := parseSettings(cfgpath)
if err != nil {
// if no settings provided allow cli to run without them.
if errors.Is(err, os.ErrNotExist) {
return nil
}
return err
}
@ -98,6 +105,10 @@ func SetupDI(ctx context.Context, cfgpath string) error {
}
func Shutdown() error {
if diInjector == nil {
return nil
}
return diInjector.Shutdown()
}

View File

@ -19,6 +19,7 @@ import (
"strconv"
"time"
rooteway "git.loyso.art/frx/eway"
"git.loyso.art/frx/eway/cmd/cli/components"
"git.loyso.art/frx/eway/internal/crypto"
"git.loyso.art/frx/eway/internal/encoding/fbs"
@ -68,23 +69,7 @@ func setupDI() cli.BeforeFunc {
func releaseDI() cli.AfterFunc {
return func(ctx context.Context, c *cli.Command) error {
log, err := components.GetLogger()
if err != nil {
return fmt.Errorf("getting logger: %w", err)
}
start := time.Now()
defer func() {
since := time.Since(start)
if err == nil {
return
}
log.Err(err).Dur("elapsed", since).Msg("shutdown finished")
}()
return components.Shutdown()
}
}
@ -92,6 +77,7 @@ func setupCLI() *cli.Command {
app := &cli.Command{
Name: "cli",
Description: "a cli for running eway logic",
Version: fmt.Sprintf("%s (%s) %s", rooteway.Version(), rooteway.Commit(), rooteway.BuildTime()),
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config",
@ -117,6 +103,12 @@ func setupCLI() *cli.Command {
return app
}
func newVersionCmd() *cli.Command {
return &cli.Command{
Name: "version",
}
}
func newCryptoCmd() *cli.Command {
return &cli.Command{
Name: "crypto",
@ -143,21 +135,6 @@ func newCryptoEncyptCmd() *cli.Command {
}
}
func newCryptoDecryptCmd() *cli.Command {
return &cli.Command{
Name: "decrypt",
Usage: "decrypt incoming text",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "text",
Aliases: []string{"t"},
Required: true,
},
},
Action: cryptoDeEncryptAction(false),
}
}
func newAppCmd() *cli.Command {
return &cli.Command{
Name: "app",
@ -1022,6 +999,7 @@ func testFBSAction(ctx context.Context, c *cli.Command) error {
func appYMLExporterAction(ctx context.Context, cmd *cli.Command) error {
port := cmd.Int("port")
src := cmd.String("src")
log, err := components.GetLogger()
if err != nil {
return fmt.Errorf("getting logger: %w", err)

27
cmd/cli/main_encoff.go Normal file
View File

@ -0,0 +1,27 @@
//go:build !encon
// +build !encon
package main
import (
"context"
"github.com/urfave/cli/v3"
)
func newCryptoDecryptCmd() *cli.Command {
return &cli.Command{
Name: "decrypt",
Usage: "decrypt incoming text",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "text",
Aliases: []string{"t"},
Required: true,
},
},
Action: func(context.Context, *cli.Command) error {
return cli.Exit("decryption is turned off", -1)
},
}
}

21
cmd/cli/main_encon.go Normal file
View File

@ -0,0 +1,21 @@
//go:build encon
// +build encon
package main
import "github.com/urfave/cli/v3"
func newCryptoDecryptCmd() *cli.Command {
return &cli.Command{
Name: "decrypt",
Usage: "decrypt incoming text",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "text",
Aliases: []string{"t"},
Required: true,
},
},
Action: cryptoDeEncryptAction(false),
}
}