From d85847ec99d44e1010a95c71579a754ac9f7c646 Mon Sep 17 00:00:00 2001 From: n-peugnet Date: Tue, 14 Sep 2021 12:35:03 +0200 Subject: add basic logger --- main.go | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 691ff25..b813954 100644 --- a/main.go +++ b/main.go @@ -1,19 +1,39 @@ package main import ( + "flag" "fmt" "os" + + "github.com/n-peugnet/dna-backup/logger" ) -func main() { +const ( + usage = "usage: dna-backup [] [--] \n\noptions:\n" +) + +var ( + logLevel int +) - if len(os.Args) != 3 { - fmt.Println("usage: dna-backup ") +func init() { + flag.IntVar(&logLevel, "v", 1, "log verbosity level (0-3)") +} + +func main() { + flag.Usage = func() { + fmt.Fprintf(flag.CommandLine.Output(), usage) + flag.PrintDefaults() + } + flag.Parse() + logger.Init(logLevel) + if len(flag.Args()) != 2 { + flag.Usage() os.Exit(1) } - source := os.Args[1] - dest := os.Args[2] + source := os.Args[0] + dest := os.Args[1] repo := NewRepo(dest) repo.Commit(source) } -- cgit v1.2.3