Jobs & Workflows https://armen.surge.sh
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

109 lines
2.2 KiB

/*
------------------------------------------------------------------------------------------------------------------------
####### cli ####### Copyright (c) 2021 mls-361 ##################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package cli
import (
"flag"
"fmt"
"io"
"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 newFlagSet(ccs *components.Components) *flag.FlagSet {
fs := flag.NewFlagSet(ccs.Application.Name(), flag.ContinueOnError)
fs.SetOutput(io.Discard)
return fs
}
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()
fmt.Println(" decrypt <string>")
fmt.Println(" encrypt <string>")
fmt.Println(" version")
fmt.Println()
fmt.Println("--@(°_°)@----------------------------------")
fmt.Println()
}
func Run(ccs *components.Components) error {
switch os.Args[1] {
case "decrypt":
return decrypt(ccs)
case "encrypt":
return encrypt(ccs)
case "jobs":
return jobs(ccs)
case "version":
version(ccs)
default:
help()
}
return nil
}
/*
######################################################################################################## @(°_°)@ #######
*/