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.
100 lines
2.1 KiB
100 lines
2.1 KiB
/* |
|
------------------------------------------------------------------------------------------------------------------------ |
|
####### 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() |
|
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 "jobs", "-j": |
|
return jobs(ccs) |
|
case "version", "-v": |
|
version(ccs) |
|
default: |
|
help() |
|
} |
|
|
|
return nil |
|
} |
|
|
|
/* |
|
######################################################################################################## @(°_°)@ ####### |
|
*/
|
|
|