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.

117 lines
2.4 KiB

/*
------------------------------------------------------------------------------------------------------------------------
####### cli ####### Copyright (c) 2021 mls-361 ##################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package cli
import (
"flag"
"fmt"
"io"
"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, args []string) error {
if len(args) != 1 {
help()
return _errArgs
}
ds, err := ccs.Crypto.DecryptString(args[0])
if err != nil {
return err
}
fmt.Println(args[0], "===>>", ds)
return nil
}
func encrypt(ccs *components.Components, args []string) error {
if len(args) != 1 {
help()
return _errArgs
}
es, err := ccs.Crypto.EncryptString(args[0])
if err != nil {
return err
}
fmt.Println(args[0], "===>>", 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.Print(`
The commands are:
decrypt <string>
encrypt <string>
jobs
create
-name <string>
-namespace <string> (required)
-type <string> (required)
-origin <string>
-priority <int>
-private <json>
-run_after <datetime> (RFC3339)
-retries <int>
-category <string>
version
--@(°_°)@-------------------------------
`)
}
func Run(ccs *components.Components, args []string) error {
switch args[0] {
case "decrypt":
return decrypt(ccs, args[1:])
case "encrypt":
return encrypt(ccs, args[1:])
case "jobs":
return jobs(ccs, args[1:])
case "version":
version(ccs)
default:
help()
}
return nil
}
/*
######################################################################################################## @(°_°)@ #######
*/