2024-02-20 13:25:31 +00:00
|
|
|
// Copyright 2024 Mikhail Klementev. All rights reserved.
|
|
|
|
// Use of this source code is governed by a AGPLv3 license
|
|
|
|
// (or later) that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
|
2024-02-26 08:55:27 +00:00
|
|
|
"code.dumpstack.io/tools/out-of-tree/api"
|
2024-02-20 13:25:31 +00:00
|
|
|
"code.dumpstack.io/tools/out-of-tree/client"
|
|
|
|
)
|
|
|
|
|
2024-02-25 18:04:02 +00:00
|
|
|
type daemonCmd struct {
|
2024-02-20 13:25:31 +00:00
|
|
|
Addr string `default:":63527"`
|
|
|
|
|
|
|
|
Job DaemonJobCmd `cmd:"" aliases:"jobs" help:"manage jobs"`
|
|
|
|
Repo DaemonRepoCmd `cmd:"" aliases:"repos" help:"manage repositories"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type DaemonJobCmd struct {
|
|
|
|
List DaemonJobsListCmd `cmd:"" help:"list jobs"`
|
|
|
|
Status DaemonJobsStatusCmd `cmd:"" help:"show job status"`
|
|
|
|
Log DaemonJobsLogsCmd `cmd:"" help:"job logs"`
|
|
|
|
}
|
|
|
|
|
2024-02-26 08:55:27 +00:00
|
|
|
type DaemonJobsListCmd struct {
|
|
|
|
Group string `help:"group uuid"`
|
|
|
|
Repo string `help:"repo name"`
|
|
|
|
Commit string `help:"commit sha"`
|
|
|
|
Status string `help:"job status"`
|
|
|
|
}
|
2024-02-20 13:25:31 +00:00
|
|
|
|
|
|
|
func (cmd *DaemonJobsListCmd) Run(dm *DaemonCmd, g *Globals) (err error) {
|
|
|
|
c := client.Client{RemoteAddr: g.RemoteAddr}
|
2024-02-26 08:55:27 +00:00
|
|
|
|
|
|
|
params := api.ListJobsParams{
|
|
|
|
Group: cmd.Group,
|
|
|
|
Repo: cmd.Repo,
|
|
|
|
Commit: cmd.Commit,
|
|
|
|
Status: api.Status(cmd.Status),
|
|
|
|
}
|
|
|
|
|
|
|
|
jobs, err := c.Jobs(params)
|
2024-02-20 13:25:31 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Error().Err(err).Msg("")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
b, err := json.MarshalIndent(jobs, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
log.Error().Err(err).Msg("")
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(string(b))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
type DaemonJobsStatusCmd struct {
|
|
|
|
UUID string `arg:""`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *DaemonJobsStatusCmd) Run(dm *DaemonCmd, g *Globals) (err error) {
|
|
|
|
c := client.Client{RemoteAddr: g.RemoteAddr}
|
|
|
|
st, err := c.JobStatus(cmd.UUID)
|
|
|
|
if err != nil {
|
|
|
|
log.Error().Err(err).Msg("")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(st)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
type DaemonJobsLogsCmd struct {
|
|
|
|
UUID string `arg:""`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd *DaemonJobsLogsCmd) Run(dm *DaemonCmd, g *Globals) (err error) {
|
|
|
|
c := client.Client{RemoteAddr: g.RemoteAddr}
|
|
|
|
logs, err := c.JobLogs(cmd.UUID)
|
|
|
|
if err != nil {
|
|
|
|
log.Error().Err(err).Msg("")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, l := range logs {
|
|
|
|
log.Info().Msg(l.Name)
|
|
|
|
fmt.Println(l.Text)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
type DaemonRepoCmd struct {
|
|
|
|
List DaemonRepoListCmd `cmd:"" help:"list repos"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type DaemonRepoListCmd struct{}
|
|
|
|
|
|
|
|
func (cmd *DaemonRepoListCmd) Run(dm *DaemonCmd, g *Globals) (err error) {
|
|
|
|
c := client.Client{RemoteAddr: g.RemoteAddr}
|
|
|
|
repos, err := c.Repos()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
b, err := json.MarshalIndent(repos, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
log.Error().Err(err).Msg("")
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(string(b))
|
|
|
|
return
|
|
|
|
}
|