Add optional --config option

This commit is contained in:
Noah 2024-03-16 17:25:18 -05:00
parent 3f88f3aac5
commit 70597d4b1f

12
main.go
View File

@ -8,25 +8,27 @@ import (
"github.com/akamensky/argparse" "github.com/akamensky/argparse"
) )
var config Configuration
func summary() { func summary() {
fmt.Println("Summary") fmt.Println("Summary")
} }
func main() { func main() {
parser := argparse.NewParser("gitivity", "Command line tool to get Gitea statistics") parser := argparse.NewParser("gitivity", "Command line tool to get Gitea statistics")
Summary := parser.NewCommand("summary", "Generate a summary of a user's activity.") 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"})
parse_err := parser.Parse(os.Args) parse_err := parser.Parse(os.Args)
if parse_err != nil { if parse_err != nil {
fmt.Print(parser.Usage(parse_err)) fmt.Print(parser.Usage(parse_err))
return
} }
config := Configuration{} config = Configuration{}
if err := config.Parse("config.lua"); err != nil { if err := config.Parse(*config_path); err != nil {
panic("Failed to parse configuration file: "+fmt.Sprint(err)) panic("Failed to parse configuration file")
} }
fmt.Printf("config.servers: %v\n", config.servers)
//client, err := gitea.NewClient(*server_name) //client, err := gitea.NewClient(*server_name)
//if err != nil { //if err != nil {