Browse Source

En cours de développement

master
mls-361 1 month ago
parent
commit
bfa54b6819
  1. 1
      Taskfile.yml
  2. 1
      go.mod
  3. 3
      go.sum
  4. 23
      internal/cli/cli.go
  5. 70
      internal/cli/jobs.go
  6. 34
      internal/cli/requestor.go

1
Taskfile.yml

@ -15,6 +15,7 @@ tasks:
- go get -u forge.chapril.org/armen/jw
- go get -u forge.chapril.org/armen/memory
- go get -u forge.chapril.org/armen/model
- go get -u forge.chapril.org/armen/requestor
- go get -u forge.chapril.org/armen/runner
- go get -u forge.chapril.org/armen/workers
- go get -u forge.chapril.org/mls-361/application

1
go.mod

@ -6,6 +6,7 @@ require (
forge.chapril.org/armen/jw v0.0.0-20210522201753-e1ba7b5b220d
forge.chapril.org/armen/memory v0.0.0-20210522203737-276e297a8222
forge.chapril.org/armen/model v0.0.0-20210522212133-8de176eea674
forge.chapril.org/armen/requestor v0.0.0-20210515121509-16eac1001434
forge.chapril.org/armen/runner v0.0.0-20210522203922-9c2d1c07ff13
forge.chapril.org/armen/workers v0.0.0-20210522204033-0382c877546d
forge.chapril.org/mls-361/application v0.0.0-20210511091326-7ec1158728fd

3
go.sum

@ -1,11 +1,14 @@
forge.chapril.org/armen/factory v0.0.0-20210522203756-6de7afffaddf h1:1JKaZKcHTxpYDgSBDfsQJyTuyt5Y86Mdv9fLEj4c8eI=
forge.chapril.org/armen/factory v0.0.0-20210522203756-6de7afffaddf/go.mod h1:mrb4t9EgvkjrbI8MtRMp5JIWl2d8q5+xP1jVToOp3Ik=
forge.chapril.org/armen/jw v0.0.0-20210512194404-698677418a88/go.mod h1:4EK5JtZMMYYWO1vjQkA9AHBwS1WD55WtROqCYc14DBo=
forge.chapril.org/armen/jw v0.0.0-20210522201753-e1ba7b5b220d h1:iuiiUmZHqEi9QvPDVWLzWisKsfLx7TH+3aPa6jxn3ZM=
forge.chapril.org/armen/jw v0.0.0-20210522201753-e1ba7b5b220d/go.mod h1:4EK5JtZMMYYWO1vjQkA9AHBwS1WD55WtROqCYc14DBo=
forge.chapril.org/armen/memory v0.0.0-20210522203737-276e297a8222 h1:z2UR0avH1a9xwoFCmL3uH95psWe5WVdgsy6N/oNrSJs=
forge.chapril.org/armen/memory v0.0.0-20210522203737-276e297a8222/go.mod h1:auVwXeRsu0+ExEVWU1FpMfMDUWM00dBThecAFtxj988=
forge.chapril.org/armen/model v0.0.0-20210522212133-8de176eea674 h1:WRZGi0q2+OAVXLFWgWrTZ7f7JGhue8cokEegatgBuMw=
forge.chapril.org/armen/model v0.0.0-20210522212133-8de176eea674/go.mod h1:Cd8OZSLlu4Gy/V/HsLUyMsIlYuph4GHIbTW66/5grtI=
forge.chapril.org/armen/requestor v0.0.0-20210515121509-16eac1001434 h1:Aso4YS6A+34JKZir1yNzQvjasm5r4ssbvsBYTMAqzt8=
forge.chapril.org/armen/requestor v0.0.0-20210515121509-16eac1001434/go.mod h1:YQpx3CD/DgVKt6LnVvR/KCAEJewyW7CTk5I6kT6JMQI=
forge.chapril.org/armen/runner v0.0.0-20210522203922-9c2d1c07ff13 h1:jWSzqd8o+WpVdRbTw734iDPriSKfO0J83z8FEZJRUuk=
forge.chapril.org/armen/runner v0.0.0-20210522203922-9c2d1c07ff13/go.mod h1:0witYwd5hEb+jwAe7YKRDyrnzHeQE3zVllWjwmkIm2U=
forge.chapril.org/armen/workers v0.0.0-20210522204033-0382c877546d h1:4gRvtp/QC5nQ9JT67sz/L5dZM9lyWpL5hIGXDvmR7mY=

23
internal/cli/cli.go

@ -7,7 +7,9 @@
package cli
import (
"flag"
"fmt"
"io"
"os"
"forge.chapril.org/mls-361/errors"
@ -17,6 +19,13 @@ import (
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()
@ -70,9 +79,9 @@ 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(" decrypt <string>")
fmt.Println(" encrypt <string>")
fmt.Println(" version")
fmt.Println()
fmt.Println("--@(°_°)@----------------------------------")
fmt.Println()
@ -80,13 +89,13 @@ func help() {
func Run(ccs *components.Components) error {
switch os.Args[1] {
case "decrypt", "-d":
case "decrypt":
return decrypt(ccs)
case "encrypt", "-e":
case "encrypt":
return encrypt(ccs)
case "jobs", "-j":
case "jobs":
return jobs(ccs)
case "version", "-v":
case "version":
version(ccs)
default:
help()

70
internal/cli/jobs.go

@ -7,17 +7,85 @@
package cli
import (
"encoding/json"
"errors"
"fmt"
"os"
"time"
"forge.chapril.org/armen/jw"
"forge.chapril.org/armen/armen/internal/components"
)
func setPrivate(job *jw.Job, value string) error {
return json.Unmarshal([]byte(value), &job.Private)
}
func setRunAfter(job *jw.Job, value string) error {
t, err := time.Parse(time.RFC3339, value)
if err != nil {
return err
}
job.RunAfter = t
return nil
}
func setCategory(job *jw.Job, value string) error {
if value == "" {
return errors.New("cannot be empty") ///////////////////////////////////////////////////////////////////////////
}
category := new(string)
*category = value
job.Category = category
return nil
}
func jobCreate(ccs *components.Components) error {
if len(os.Args) < 4 {
help()
return _errArgs
}
fs := newFlagSet(ccs)
job := new(jw.Job)
fs.StringVar(&job.Name, "name", "", "")
fs.StringVar(&job.Namespace, "namespace", "", "")
fs.StringVar(&job.Type, "type", "", "")
fs.StringVar(&job.Origin, "origin", "", "")
fs.IntVar((*int)(&job.Priority), "priority", 0, "")
fs.Func("private", "", func(value string) error { return setPrivate(job, value) })
fs.Func("run_after", "", func(value string) error { return setRunAfter(job, value) })
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 {
return err
}
model, err := newRequestor(ccs)
if err != nil {
return err
}
nj, err := model.CreateJob(job)
if err != nil {
return err
}
data, err := json.MarshalIndent(nj, "", " ")
if err != nil {
fmt.Printf("%+v\n\n", nj)
return err
}
fmt.Println(string(data))
return nil
}
@ -28,7 +96,7 @@ func jobs(ccs *components.Components) error {
}
switch os.Args[2] {
case "create", "-c":
case "create":
return jobCreate(ccs)
default:
help()

34
internal/cli/requestor.go

@ -0,0 +1,34 @@
/*
------------------------------------------------------------------------------------------------------------------------
####### cli ####### Copyright (c) 2021 mls-361 ##################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package cli
import (
"fmt"
"forge.chapril.org/armen/jw"
"forge.chapril.org/armen/requestor"
"forge.chapril.org/armen/armen/internal/components"
)
func newRequestor(ccs *components.Components) (jw.Model, error) {
cfg := ccs.Config.Server()
endpoint := &requestor.Endpoint{
URL: fmt.Sprintf("http://localhost:%d", cfg.Port),
}
rc := &requestor.Config{
Logger: ccs.Logger,
Endpoints: []*requestor.Endpoint{endpoint},
}
return requestor.New(rc)
}
/*
######################################################################################################## @(°_°)@ #######
*/
Loading…
Cancel
Save