Commit daaefa53 authored by Kirill Unitsaev's avatar Kirill Unitsaev

repo: add --format flag to deferred info command

- Add DeferredInfo struct for JSON serialization - Add JSON output support to deferred info command
parent e9d6dc3d
package repo
import (
"ximperconf/config"
"context"
"fmt"
"io"
"net/http"
"os"
"regexp"
"ximperconf/config"
"ximperconf/ui"
"github.com/fatih/color"
"github.com/urfave/cli/v3"
)
type DeferredInfo struct {
LastUpdate string `json:"last_update"`
ArchiveDate string `json:"archive_date"`
}
var (
reLastUpdate = regexp.MustCompile(`Last update date: ([0-9:\- ]+)`)
reArchiveDate = regexp.MustCompile(`Sisyphus archive date: ([0-9\-]+)`)
......@@ -73,6 +78,13 @@ func DeferredInfoCommand(ctx context.Context, cmd *cli.Command) error {
lastUpdate := deferredLastUpdate(html)
archiveDate := deferredArchiveDate(html)
if config.IsJSON(cmd) {
return ui.PrintJSON(DeferredInfo{
LastUpdate: lastUpdate,
ArchiveDate: archiveDate,
})
}
color.Green("Deferred:")
fmt.Printf(" Последнее обновление: %s\n", lastUpdate)
fmt.Printf(" Дата архива: %s\n", archiveDate)
......
package repo
import "github.com/urfave/cli/v3"
import (
"ximperconf/config"
"github.com/urfave/cli/v3"
)
func CommandList() *cli.Command {
return &cli.Command{
......@@ -12,8 +16,11 @@ func CommandList() *cli.Command {
Usage: "Deferred repo",
Commands: []*cli.Command{
{
Name: "info",
Usage: "Deferred repo info",
Name: "info",
Usage: "Deferred repo info",
Flags: []cli.Flag{
config.FormatFlag,
},
Action: DeferredInfoCommand,
},
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment