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.
115 lines
2.7 KiB
115 lines
2.7 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.Println() |
|
fmt.Println("The commands are:") |
|
fmt.Println() |
|
fmt.Println(" decrypt <string>") |
|
fmt.Println(" encrypt <string>") |
|
fmt.Println(" jobs") |
|
fmt.Println(" create") |
|
fmt.Println(" -name <string>") |
|
fmt.Println(" -namespace <string> (required)") |
|
fmt.Println(" -type <string> (required)") |
|
fmt.Println(" -origin <string>") |
|
fmt.Println(" -priority <int>") |
|
fmt.Println(" -private <json>") |
|
fmt.Println(" -run_after <datetime> (RFC3339)") |
|
fmt.Println(" -retries <int>") |
|
fmt.Println(" -category <string>") |
|
fmt.Println(" version") |
|
fmt.Println() |
|
fmt.Println("--@(°_°)@----------------------------------") |
|
fmt.Println() |
|
} |
|
|
|
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 |
|
} |
|
|
|
/* |
|
######################################################################################################## @(°_°)@ ####### |
|
*/
|
|
|