Browse Source

En cours de développement

master
mls-361 9 months ago
parent
commit
0c0899322d
  1. 2
      cmd/main.go
  2. 31
      internal/cli/cli.go
  3. 15
      internal/cli/jobs.go

2
cmd/main.go

@ -135,7 +135,7 @@ func run() error {
}
if len(os.Args) > 1 {
return app.OnError(cli.Run(ccs))
return app.OnError(cli.Run(ccs, os.Args[1:]))
}
group, endCh := waitEnd(ccs.Server)

31
internal/cli/cli.go

@ -10,7 +10,6 @@ import (
"flag"
"fmt"
"io"
"os"
"forge.chapril.org/mls-361/errors"
@ -26,38 +25,34 @@ func newFlagSet(ccs *components.Components) *flag.FlagSet {
return fs
}
func decrypt(ccs *components.Components) error {
if len(os.Args) != 3 {
func decrypt(ccs *components.Components, args []string) error {
if len(args) != 1 {
help()
return _errArgs
}
es := os.Args[2]
ds, err := ccs.Crypto.DecryptString(es)
ds, err := ccs.Crypto.DecryptString(args[0])
if err != nil {
return err
}
fmt.Println(es, "===>>", ds)
fmt.Println(args[0], "===>>", ds)
return nil
}
func encrypt(ccs *components.Components) error {
if len(os.Args) != 3 {
func encrypt(ccs *components.Components, args []string) error {
if len(args) != 1 {
help()
return _errArgs
}
ds := os.Args[2]
es, err := ccs.Crypto.EncryptString(ds)
es, err := ccs.Crypto.EncryptString(args[0])
if err != nil {
return err
}
fmt.Println(ds, "===>>", es)
fmt.Println(args[0], "===>>", es)
return nil
}
@ -98,14 +93,14 @@ func help() {
fmt.Println()
}
func Run(ccs *components.Components) error {
switch os.Args[1] {
func Run(ccs *components.Components, args []string) error {
switch args[0] {
case "decrypt":
return decrypt(ccs)
return decrypt(ccs, args[1:])
case "encrypt":
return encrypt(ccs)
return encrypt(ccs, args[1:])
case "jobs":
return jobs(ccs)
return jobs(ccs, args[1:])
case "version":
version(ccs)
default:

15
internal/cli/jobs.go

@ -10,7 +10,6 @@ import (
"encoding/json"
"errors"
"fmt"
"os"
"time"
"forge.chapril.org/armen/jw"
@ -45,8 +44,8 @@ func setCategory(job *jw.Job, value string) error {
return nil
}
func jobCreate(ccs *components.Components) error {
if len(os.Args) < 4 {
func jobCreate(ccs *components.Components, args []string) error {
if len(args) < 2 {
help()
return _errArgs
}
@ -64,7 +63,7 @@ func jobCreate(ccs *components.Components) error {
fs.IntVar(&job.Retries, "retries", 0, "")
fs.Func("category", "", func(value string) error { return setCategory(job, value) })
if err := fs.Parse(os.Args[3:]); err != nil {
if err := fs.Parse(args); err != nil {
return err
}
@ -89,15 +88,15 @@ func jobCreate(ccs *components.Components) error {
return nil
}
func jobs(ccs *components.Components) error {
if len(os.Args) < 3 {
func jobs(ccs *components.Components, args []string) error {
if len(args) < 1 {
help()
return _errArgs
}
switch os.Args[2] {
switch args[0] {
case "create":
return jobCreate(ccs)
return jobCreate(ccs, args[1:])
default:
help()
}

Loading…
Cancel
Save