Browse Source

En cours de développement

master
mls-361 8 months ago
parent
commit
989aaa06f3
  1. 2
      internal/cli/cli.go
  2. 42
      internal/cli/jobs.go
  3. 121
      internal/cmdline/cmdline.go

2
internal/cli/cli.go

@ -84,6 +84,8 @@ func Run(ccs *components.Components) error {
return decrypt(ccs)
case "encrypt", "-e":
return encrypt(ccs)
case "jobs", "-j":
return jobs(ccs)
case "version", "-v":
version(ccs)
default:

42
internal/cli/jobs.go

@ -0,0 +1,42 @@
/*
------------------------------------------------------------------------------------------------------------------------
####### cli ####### Copyright (c) 2021 mls-361 ##################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package cli
import (
"os"
"forge.chapril.org/armen/armen/internal/components"
)
func jobCreate(ccs *components.Components) error {
if len(os.Args) < 4 {
help()
return _errArgs
}
return nil
}
func jobs(ccs *components.Components) error {
if len(os.Args) < 3 {
help()
return _errArgs
}
switch os.Args[2] {
case "create", "-c":
return jobCreate(ccs)
default:
help()
}
return nil
}
/*
######################################################################################################## @(°_°)@ #######
*/

121
internal/cmdline/cmdline.go

@ -1,121 +0,0 @@
/*
------------------------------------------------------------------------------------------------------------------------
####### cmdline ####### Copyright (c) 2021 mls-361 ################################################# MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package cmdline
import (
"fmt"
"os"
"forge.chapril.org/mls-361/application"
"forge.chapril.org/mls-361/crypto"
"forge.chapril.org/mls-361/errors"
)
const _errArgs = errors.Sentinel("not enough or too many arguments")
func newCrypto(app *application.Application) (*crypto.Crypto, error) {
c := crypto.New()
key, ok := app.LookupEnv("KEY")
if !ok {
return c, nil
}
return c, c.SetKey(key)
}
func decrypt(app *application.Application) error {
if len(os.Args) != 3 {
help(app)
return _errArgs
}
es := os.Args[2]
c, err := newCrypto(app)
if err != nil {
return err
}
ds, err := c.DecryptString(es)
if err != nil {
return err
}
fmt.Println(es, "===>>", ds)
return nil
}
func encrypt(app *application.Application) error {
if len(os.Args) != 3 {
help(app)
return _errArgs
}
ds := os.Args[2]
c, err := newCrypto(app)
if err != nil {
return err
}
es, err := c.EncryptString(ds)
if err != nil {
return err
}
fmt.Println(ds, "===>>", es)
return nil
}
func version(app *application.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(app *application.Application) {
fmt.Println()
fmt.Println(" commands:")
fmt.Println(" [-[-]]decrypt|-d|-D <string>")
fmt.Println(" [-[-]]encrypt|-e|-E <string>")
fmt.Println(" [-[-]]version|-v|-V")
fmt.Println()
fmt.Println("--@(°_°)@----------------------------------")
fmt.Println()
}
// Parse AFAIRE.
func Parse(app *application.Application) (bool, error) {
if len(os.Args) == 1 {
return false, nil
}
switch os.Args[1] {
case "decrypt", "-decrypt", "--decrypt", "-d", "-D":
return true, decrypt(app)
case "encrypt", "-encrypt", "--encrypt", "-e", "-E":
return true, encrypt(app)
case "version", "-version", "--version", "-v", "-V":
version(app)
default:
help(app)
}
return true, nil
}
/*
######################################################################################################## @(°_°)@ #######
*/
Loading…
Cancel
Save