From 89fb0a85f78a415477e450b0091d8c2b994b687d Mon Sep 17 00:00:00 2001 From: n-peugnet Date: Thu, 14 Oct 2021 18:07:17 +0200 Subject: start dir exporter --- main.go | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index ada0252..ae180b9 100644 --- a/main.go +++ b/main.go @@ -42,19 +42,25 @@ var ( logLevel int chunkSize int format string + trackSize int ) -var commit = command{flag.NewFlagSet("commit", flag.ExitOnError), commitMain, +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, +var Restore = command{flag.NewFlagSet("restore", flag.ExitOnError), restoreMain, "[] [--] ", "Restore the last version from repo into folder ", } +var Export = command{flag.NewFlagSet("export", flag.ExitOnError), exportMain, + "[] [--] ", + "Export versions from repo into folder ", +} var subcommands = map[string]command{ - commit.Flag.Name(): commit, - restore.Flag.Name(): restore, + Commit.Flag.Name(): Commit, + Restore.Flag.Name(): Restore, + Export.Flag.Name(): Export, } func init() { @@ -71,6 +77,8 @@ func init() { s.Flag.IntVar(&logLevel, "v", 3, "log verbosity level (0-4)") s.Flag.IntVar(&chunkSize, "c", 8<<10, "chunk size") } + Export.Flag.StringVar(&format, "format", "dir", "format of the export (dir, csv)") + Export.Flag.IntVar(&trackSize, "track", 1020, "size of a DNA track") } func main() { @@ -104,8 +112,8 @@ func commitMain(args []string) error { } source := args[0] dest := args[1] - repo := repo.NewRepo(dest, chunkSize) - repo.Commit(source) + r := repo.NewRepo(dest, chunkSize) + r.Commit(source) return nil } @@ -115,7 +123,25 @@ func restoreMain(args []string) error { } source := args[0] dest := args[1] - repo := repo.NewRepo(source, chunkSize) - repo.Restore(dest) + r := repo.NewRepo(source, chunkSize) + r.Restore(dest) + return nil +} + +func exportMain(args []string) error { + if len(args) != 2 { + return fmt.Errorf("wrong number args") + } + source := args[0] + dest := args[1] + r := repo.NewRepo(source, chunkSize) + switch format { + case "dir": + r.ExportDir(dest, trackSize) + case "csv": + fmt.Println("csv") + default: + logger.Errorf("unknown format %s", format) + } return nil } -- cgit v1.2.3