Browse Source

En cours de développement

master
mls-361 2 months ago
parent
commit
a2544a9d69
  1. 14
      cmd/main.go
  2. 97
      internal/cli/cli.go
  3. 1
      internal/components/components.go

14
cmd/main.go

@ -18,7 +18,7 @@ import (
"forge.chapril.org/mls-361/errors"
"forge.chapril.org/armen/armen/internal/api"
"forge.chapril.org/armen/armen/internal/cmdline"
"forge.chapril.org/armen/armen/internal/cli"
"forge.chapril.org/armen/armen/internal/components"
"forge.chapril.org/armen/armen/internal/config"
"forge.chapril.org/armen/armen/internal/crypto"
@ -68,6 +68,10 @@ func buildComponents(ccs *components.Components) error {
return errors.WithMessage(err, "model") ////////////////////////////////////////////////////////////////////////
}
if len(os.Args) > 1 {
return nil
}
ccs.Router = router.Build(ccs)
ccs.Server, err = server.Build(ccs)
@ -115,10 +119,6 @@ func run() error {
return app.OnError(err)
}
if end, err := cmdline.Parse(app); end || err != nil {
return app.OnError(err)
}
ccs := components.New(app)
defer ccs.Shutdown()
@ -134,6 +134,10 @@ func run() error {
return app.OnError(err)
}
if len(os.Args) > 1 {
return app.OnError(cli.Run(ccs))
}
group, endCh := waitEnd(ccs.Server)
ccs.Startup()

97
internal/cli/cli.go

@ -0,0 +1,97 @@
/*
------------------------------------------------------------------------------------------------------------------------
####### cli ####### Copyright (c) 2021 mls-361 ##################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package cli
import (
"fmt"
"os"
"forge.chapril.org/mls-361/errors"
"forge.chapril.org/armen/armen/internal/components"
)
const _errArgs = errors.Sentinel("not enough or too many arguments")
func decrypt(ccs *components.Components) error {
if len(os.Args) != 3 {
help()
return _errArgs
}
es := os.Args[2]
ds, err := ccs.Crypto.DecryptString(es)
if err != nil {
return err
}
fmt.Println(es, "===>>", ds)
return nil
}
func encrypt(ccs *components.Components) error {
if len(os.Args) != 3 {
help()
return _errArgs
}
ds := os.Args[2]
es, err := ccs.Crypto.EncryptString(ds)
if err != nil {
return err
}
fmt.Println(ds, "===>>", es)
return nil
}
func version(ccs *components.Components) {
app := ccs.Application
fmt.Println()
fmt.Println(" application :", app.Name(), "v"+app.Version())
fmt.Println(" built at :", app.BuiltAt().Format("2006-01-02 15:04:05"))
fmt.Println(" copyright :", "mls-361")
fmt.Println(" license :", "MIT")
fmt.Println()
fmt.Println("--@(°_°)@----------------------------------")
fmt.Println()
}
func help() {
fmt.Println()
fmt.Println(" commands:")
fmt.Println(" decrypt|-d <string>")
fmt.Println(" encrypt|-e <string>")
fmt.Println(" version|-v")
fmt.Println()
fmt.Println("--@(°_°)@----------------------------------")
fmt.Println()
}
func Run(ccs *components.Components) error {
switch os.Args[1] {
case "decrypt", "-d":
return decrypt(ccs)
case "encrypt", "-e":
return encrypt(ccs)
case "version", "-v":
version(ccs)
default:
help()
}
return nil
}
/*
######################################################################################################## @(°_°)@ #######
*/

1
internal/components/components.go

@ -40,6 +40,7 @@ type Config interface {
// Crypto AFAIRE.
type Crypto interface {
DecryptString(text string) (string, error)
EncryptString(text string) (string, error)
}
// Logger AFAIRE.

Loading…
Cancel
Save