62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"code.gitea.io/sdk/gitea"
|
|
"github.com/akamensky/argparse"
|
|
)
|
|
|
|
var config Configuration
|
|
var Servers map[string]*gitea.Client
|
|
|
|
func main() {
|
|
parser := argparse.NewParser("gitivity", "Command line tool to get Gitea statistics")
|
|
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.")
|
|
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"})
|
|
|
|
parse_err := parser.Parse(os.Args)
|
|
if parse_err != nil {
|
|
fmt.Print(parser.Usage(parse_err))
|
|
return
|
|
}
|
|
|
|
config = Configuration{}
|
|
Servers = make(map[string]*gitea.Client)
|
|
if err := config.Parse(*config_path); err != nil {
|
|
panic("Failed to parse configuration file")
|
|
}
|
|
|
|
for _, server := range config.servers {
|
|
if *server_option != "" && strings.ToLower(server.servername) != strings.ToLower(*server_option) {
|
|
continue
|
|
}
|
|
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)
|
|
}
|
|
|
|
if Times.Happened() {
|
|
times()
|
|
} else if Summary.Happened() {
|
|
summary()
|
|
} else if Feed.Happened() {
|
|
//feed()
|
|
}
|
|
}
|