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 package repo
import ( import (
"ximperconf/config"
"context" "context"
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
"os" "os"
"regexp" "regexp"
"ximperconf/config"
"ximperconf/ui"
"github.com/fatih/color" "github.com/fatih/color"
"github.com/urfave/cli/v3" "github.com/urfave/cli/v3"
) )
type DeferredInfo struct {
LastUpdate string `json:"last_update"`
ArchiveDate string `json:"archive_date"`
}
var ( var (
reLastUpdate = regexp.MustCompile(`Last update date: ([0-9:\- ]+)`) reLastUpdate = regexp.MustCompile(`Last update date: ([0-9:\- ]+)`)
reArchiveDate = regexp.MustCompile(`Sisyphus archive date: ([0-9\-]+)`) reArchiveDate = regexp.MustCompile(`Sisyphus archive date: ([0-9\-]+)`)
...@@ -73,6 +78,13 @@ func DeferredInfoCommand(ctx context.Context, cmd *cli.Command) error { ...@@ -73,6 +78,13 @@ func DeferredInfoCommand(ctx context.Context, cmd *cli.Command) error {
lastUpdate := deferredLastUpdate(html) lastUpdate := deferredLastUpdate(html)
archiveDate := deferredArchiveDate(html) archiveDate := deferredArchiveDate(html)
if config.IsJSON(cmd) {
return ui.PrintJSON(DeferredInfo{
LastUpdate: lastUpdate,
ArchiveDate: archiveDate,
})
}
color.Green("Deferred:") color.Green("Deferred:")
fmt.Printf(" Последнее обновление: %s\n", lastUpdate) fmt.Printf(" Последнее обновление: %s\n", lastUpdate)
fmt.Printf(" Дата архива: %s\n", archiveDate) fmt.Printf(" Дата архива: %s\n", archiveDate)
......
package repo package repo
import "github.com/urfave/cli/v3" import (
"ximperconf/config"
"github.com/urfave/cli/v3"
)
func CommandList() *cli.Command { func CommandList() *cli.Command {
return &cli.Command{ return &cli.Command{
...@@ -14,6 +18,9 @@ func CommandList() *cli.Command { ...@@ -14,6 +18,9 @@ func CommandList() *cli.Command {
{ {
Name: "info", Name: "info",
Usage: "Deferred repo info", Usage: "Deferred repo info",
Flags: []cli.Flag{
config.FormatFlag,
},
Action: DeferredInfoCommand, 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