add repo subcommands

parent e9c9e566
...@@ -11,9 +11,14 @@ type HyprEnv struct { ...@@ -11,9 +11,14 @@ type HyprEnv struct {
UserModulesDir string UserModulesDir string
} }
type RepoEnv struct {
DeferredInfoURL string
}
type Environment struct { type Environment struct {
Version string Version string
Hyprland *HyprEnv Hyprland *HyprEnv
Repo *RepoEnv
} }
var Env Environment var Env Environment
...@@ -52,5 +57,9 @@ func InitConfig() error { ...@@ -52,5 +57,9 @@ func InitConfig() error {
} }
} }
Env.Repo = &RepoEnv{
DeferredInfoURL: "https://download.etersoft.ru/pub/Etersoft/Sisyphus/Deferred_Info.html",
}
return nil return nil
} }
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"os" "os"
"ximperconf/config" "ximperconf/config"
"ximperconf/hyprland" "ximperconf/hyprland"
"ximperconf/repo"
"github.com/urfave/cli/v3" "github.com/urfave/cli/v3"
) )
...@@ -19,6 +20,7 @@ func main() { ...@@ -19,6 +20,7 @@ func main() {
EnableShellCompletion: true, EnableShellCompletion: true,
Version: config.Env.Version, Version: config.Env.Version,
Commands: []*cli.Command{ Commands: []*cli.Command{
repo.CommandList(),
hyprland.CommandList(), hyprland.CommandList(),
{ {
Name: "help", Name: "help",
......
package repo
import (
"ximperconf/config"
"context"
"fmt"
"io"
"net/http"
"os"
"regexp"
"github.com/fatih/color"
"github.com/urfave/cli/v3"
)
var (
reLastUpdate = regexp.MustCompile(`Last update date: ([0-9:\- ]+)`)
reArchiveDate = regexp.MustCompile(`Sisyphus archive date: ([0-9\-]+)`)
)
func deferredGetHTML() string {
resp, err := http.Get(config.Env.Repo.DeferredInfoURL)
if err != nil {
color.Red("Ошибка получения данных")
os.Exit(1)
}
defer resp.Body.Close()
data, err := io.ReadAll(resp.Body)
if err != nil {
color.Red("Ошибка получения данных")
os.Exit(1)
}
return string(data)
}
func deferredLastUpdate(html string) string {
if m := reLastUpdate.FindStringSubmatch(html); m != nil {
return m[1]
}
return ""
}
func DeferredLastUpdateCommand(ctx context.Context, cmd *cli.Command) error {
html := deferredGetHTML()
lastUpdate := deferredLastUpdate(html)
fmt.Println(lastUpdate)
return nil
}
func deferredArchiveDate(html string) string {
if m := reArchiveDate.FindStringSubmatch(html); m != nil {
return m[1]
}
return ""
}
func DeferredArchiveDateCommand(ctx context.Context, cmd *cli.Command) error {
html := deferredGetHTML()
archiveDate := deferredArchiveDate(html)
fmt.Println(archiveDate)
return nil
}
func DeferredInfoCommand(ctx context.Context, cmd *cli.Command) error {
html := deferredGetHTML()
lastUpdate := deferredLastUpdate(html)
archiveDate := deferredArchiveDate(html)
color.Green("Deferred:")
fmt.Printf(" Последнее обновление: %s\n", lastUpdate)
fmt.Printf(" Дата архива: %s\n", archiveDate)
return nil
}
package repo
import "github.com/urfave/cli/v3"
func CommandList() *cli.Command {
return &cli.Command{
Name: "repo",
Usage: "Ximper repos",
Commands: []*cli.Command{
{
Name: "deferred",
Usage: "Deferred repo",
Commands: []*cli.Command{
{
Name: "info",
Usage: "Deferred repo info",
Action: DeferredInfoCommand,
},
{
Name: "date",
Usage: "Sisyphus archive date",
Action: DeferredArchiveDateCommand,
},
{
Name: "last-update",
Usage: "Date of last update",
Action: DeferredLastUpdateCommand,
},
},
},
},
}
}
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