gitivity/main.go

62 lines
1.6 KiB
Go
Raw Normal View History

2024-03-16 14:08:19 -05:00
package main
import (
"fmt"
"os"
"strings"
2024-03-16 14:08:19 -05:00
"code.gitea.io/sdk/gitea"
2024-03-16 17:05:19 -05:00
"github.com/akamensky/argparse"
2024-03-16 14:08:19 -05:00
)
2024-03-16 17:25:18 -05:00
var config Configuration
var Servers map[string]*gitea.Client
2024-03-16 17:25:18 -05:00
2024-03-16 14:08:19 -05:00
func main() {
2024-03-16 17:05:19 -05:00
parser := argparse.NewParser("gitivity", "Command line tool to get Gitea statistics")
2024-03-17 17:59:56 -05:00
Times := parser.NewCommand("times", "Get a user's tracked times.")
Summary := parser.NewCommand("summary", "Display a summary of a user's activity.")
Feed := parser.NewCommand("feed", "Display the user's activity feed.")
2024-03-16 17:25:18 -05:00
config_path := parser.String("c", "config", &argparse.Options{Required: false, Help: "Configuration file", Default: "./config.lua"})
server_option := parser.String("s", "server", &argparse.Options{Required: false, Help: "Specific server to use"})
2024-03-16 17:05:19 -05:00
parse_err := parser.Parse(os.Args)
if parse_err != nil {
fmt.Print(parser.Usage(parse_err))
2024-03-16 17:25:18 -05:00
return
2024-03-16 14:08:19 -05:00
}
2024-03-16 17:05:19 -05:00
2024-03-16 17:25:18 -05:00
config = Configuration{}
Servers = make(map[string]*gitea.Client)
2024-03-16 17:25:18 -05:00
if err := config.Parse(*config_path); err != nil {
panic("Failed to parse configuration file")
2024-03-16 14:08:19 -05:00
}
2024-03-16 17:05:19 -05:00
for _, server := range config.servers {
if *server_option != "" && strings.ToLower(server.servername) != strings.ToLower(*server_option) {
continue
}
2024-03-16 21:17:40 -05:00
client_opts := []gitea.ClientOption{
gitea.SetToken(server.token),
}
client, err := gitea.NewClient(server.url, client_opts...)
if err != nil {
fmt.Printf("Failed to create Gitea client! (%s)\n", err)
os.Exit(1)
}
Servers[server.servername] = client
}
if len(Servers) == 0 {
println("No servers configured / specified")
os.Exit(0)
}
2024-03-17 17:59:56 -05:00
2024-03-16 21:17:40 -05:00
if Times.Happened() {
2024-03-17 17:59:56 -05:00
times()
} else if Summary.Happened() {
summary()
} else if Feed.Happened() {
feed()
2024-03-17 17:59:56 -05:00
}
2024-03-16 14:08:19 -05:00
}