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.

111 lines
2.4 KiB

/*
------------------------------------------------------------------------------------------------------------------------
####### cli ####### Copyright (c) 2021 mls-361 ##################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
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
}
func jobs(ccs *components.Components) error {
if len(os.Args) < 3 {
help()
return _errArgs
}
switch os.Args[2] {
case "create":
return jobCreate(ccs)
default:
help()
}
return nil
}
/*
######################################################################################################## @(°_°)@ #######
*/