From 9b9710511b0dbe51ac030ef908f9468103b0bd0a Mon Sep 17 00:00:00 2001 From: n-peugnet Date: Wed, 6 Oct 2021 11:25:10 +0200 Subject: refactor main and logger --- main.go | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index cf208c9..51cfac2 100644 --- a/main.go +++ b/main.go @@ -10,30 +10,34 @@ import ( type command struct { Flag *flag.FlagSet + Run func([]string) error Usage string Help string - Run func([]string) error } const ( - name = "dna-backup" - baseUsage = " [] [--] " - commitUsage = "[] [--] " - commitHelp = "Create a new version of folder into repo " - restoreUsage = "[] [--] " - restoreHelp = "Restore the last version from repo into folder " + name = "dna-backup" + baseUsage = " [] [--] " ) var ( - logLevel int - commitCmd = flag.NewFlagSet("commit", flag.ExitOnError) - restoreCmd = flag.NewFlagSet("restore", flag.ExitOnError) - subcommands = map[string]command{ - commitCmd.Name(): {commitCmd, commitUsage, commitHelp, commitMain}, - restoreCmd.Name(): {restoreCmd, restoreUsage, restoreHelp, restoreMain}, - } + logLevel int + format string ) +var commit = command{flag.NewFlagSet("commit", flag.ExitOnError), commitMain, + "[] [--] ", + "Create a new version of folder into repo ", +} +var restore = command{flag.NewFlagSet("restore", flag.ExitOnError), restoreMain, + "[] [--] ", + "Restore the last version from repo into folder ", +} +var subcommands = map[string]command{ + commit.Flag.Name(): commit, + restore.Flag.Name(): restore, +} + func init() { // init default help message flag.Usage = func() { -- cgit v1.2.3