diff --git a/.gitea/workflows/demo.yaml b/.gitea/workflows/demo.yaml new file mode 100644 index 0000000..37605f2 --- /dev/null +++ b/.gitea/workflows/demo.yaml @@ -0,0 +1,19 @@ +name: Gitea Actions Demo +run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀 +on: [push] + +jobs: + Explore-Gitea-Actions: + runs-on: linux_arm64 + steps: + - run: echo "The job was automatically triggered by a ${{ gitea.event_name }} event." + - run: echo "This job is now running on a ${{ runner.os }} server hosted by Gitea!" + - run: echo "The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}." + - name: Check out repository code + uses: actions/checkout@v4 + - run: echo "The ${{ gitea.repository }} repository has been cloned to the runner." + - run: echo "The workflow is now ready to test your code on the runner." + - name: List files in the repository + run: | + ls ${{ gitea.workspace }} + - run: echo "This job's status is ${{ job.status }}." diff --git a/.gitignore b/.gitignore index 3d9ddc7..e2d9d9c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ database bin *.xml +Makefile diff --git a/buildinfo.go b/buildinfo.go new file mode 100644 index 0000000..b6ca9a4 --- /dev/null +++ b/buildinfo.go @@ -0,0 +1,36 @@ +package eway + +import ( + "sync" + "time" +) + +var ( + version string = "v0.0.0" + commit string = "0000000" + buildTimeStr string + + buildTime time.Time + + parseOnce sync.Once +) + +func Version() string { + return version +} + +func Commit() string { + return commit +} + +func BuildTime() time.Time { + parseOnce.Do(func() { + if buildTimeStr == "" { + return + } + + buildTime, _ = time.Parse(buildTimeStr, time.RFC3339) + }) + + return buildTime +} diff --git a/cmd/cli/components/di.go b/cmd/cli/components/di.go index c3a2dc3..56bf925 100644 --- a/cmd/cli/components/di.go +++ b/cmd/cli/components/di.go @@ -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() } diff --git a/cmd/cli/main.go b/cmd/cli/main.go index c45b4b5..c1144b5 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -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) diff --git a/cmd/cli/main_encoff.go b/cmd/cli/main_encoff.go new file mode 100644 index 0000000..95032b0 --- /dev/null +++ b/cmd/cli/main_encoff.go @@ -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) + }, + } +} diff --git a/cmd/cli/main_encon.go b/cmd/cli/main_encon.go new file mode 100644 index 0000000..fcb59a0 --- /dev/null +++ b/cmd/cli/main_encon.go @@ -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), + } +} diff --git a/internal/crypto/decrypt_on.go b/internal/crypto/decrypt.go similarity index 95% rename from internal/crypto/decrypt_on.go rename to internal/crypto/decrypt.go index 8cb5d0e..33fb711 100644 --- a/internal/crypto/decrypt_on.go +++ b/internal/crypto/decrypt.go @@ -1,6 +1,3 @@ -//go:build encon -// +build encon - package crypto import ( diff --git a/internal/crypto/decrypt_off.go b/internal/crypto/decrypt_off.go deleted file mode 100644 index 08795d6..0000000 --- a/internal/crypto/decrypt_off.go +++ /dev/null @@ -1,10 +0,0 @@ -//go:build !encon -// +build !encon - -package crypto - -import "git.loyso.art/frx/eway/internal/entity" - -func Decrypt(hexedcipher string) (plaintext string, err error) { - return "", entity.SimpleError("this feature turned off") -}