Add --server flag to specify a specific server for activity stats
This commit is contained in:
parent
70597d4b1f
commit
0d212a558c
40
main.go
40
main.go
@ -1,23 +1,33 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
//"code.gitea.io/sdk/gitea"
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/akamensky/argparse"
|
||||
)
|
||||
|
||||
var config Configuration
|
||||
var Clients map[string]*gitea.Client
|
||||
|
||||
func summary() {
|
||||
fmt.Println("Summary")
|
||||
for name, client := range Clients {
|
||||
server_version, _, err := client.ServerVersion()
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to get server version! (%s)\n", err)
|
||||
}
|
||||
fmt.Printf("%s - %s\n", name, server_version)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
parser := argparse.NewParser("gitivity", "Command line tool to get Gitea statistics")
|
||||
Summary := parser.NewCommand("summary", "Generate a summary of a user's activity.")
|
||||
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 {
|
||||
@ -25,20 +35,28 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
Clients = make(map[string]*gitea.Client)
|
||||
config = Configuration{}
|
||||
if err := config.Parse(*config_path); err != nil {
|
||||
panic("Failed to parse configuration file")
|
||||
}
|
||||
|
||||
//client, err := gitea.NewClient(*server_name)
|
||||
//if err != nil {
|
||||
// fmt.Printf("Failed to create Gitea client! (%s)\n", err)
|
||||
// os.Exit(1)
|
||||
//}
|
||||
//server_version, _, err := client.ServerVersion()
|
||||
//if err != nil {
|
||||
// fmt.Printf("Failed to get server version! (%s)\n", err)
|
||||
//}
|
||||
for _, server := range config.servers {
|
||||
if *server_option != "" && strings.ToLower(server.servername) != strings.ToLower(*server_option) {
|
||||
continue
|
||||
}
|
||||
client, err := gitea.NewClient(server.url)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to create Gitea client! (%s)\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
Clients[server.servername] = client
|
||||
}
|
||||
if len(Clients) == 0 {
|
||||
println("No servers configured / specified")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if Summary.Happened() {
|
||||
summary()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user