From 0844490d791de61a875eb629685bca93e782cac6 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Thu, 22 Apr 2021 11:29:04 +0200 Subject: [PATCH] Refactor command organization --- command.go | 20 ++++++++++++++++++++ commit.go | 15 --------------- config.go | 2 +- seafile_recovery.go | 6 +++--- 4 files changed, 24 insertions(+), 19 deletions(-) create mode 100644 command.go diff --git a/command.go b/command.go new file mode 100644 index 0000000..6aa52e8 --- /dev/null +++ b/command.go @@ -0,0 +1,20 @@ +package main + +import( + "log" +) + +func cmdHead(config configCollect) { + rc := NewRepoCommits(config) + + rc.CollectDescs() + log.Println("Repo contains", len(rc.CommitDesc), "commits") + + rc.CollectContent() + rc.BuildGraph() + rc.FindLeafs() + log.Println("Repo has", len(rc.Leafs), "leafs") + + rc.ChooseHead() + log.Println("Proposing following HEAD:\n"+rc.Head.Content.String()) +} diff --git a/commit.go b/commit.go index 0b464f9..416ee83 100644 --- a/commit.go +++ b/commit.go @@ -55,21 +55,6 @@ RepoDesc: %s `, *c.RootId, *c.CreatorName, *c.Creator, *c.Description, time.Unix(c.Ctime, 0), *c.RepoName, *c.RepoDesc) } -func cmdCommit(config configCollect) { - rc := NewRepoCommits(config) - - rc.CollectDescs() - log.Println("Repo contains", len(rc.CommitDesc), "commits") - - rc.CollectContent() - rc.BuildGraph() - rc.FindLeafs() - log.Println("Repo has", len(rc.Leafs), "leafs") - - rc.ChooseHead() - log.Println("Proposing following HEAD:\n"+rc.Head.Content.String()) -} - func NewRepoCommits (config configCollect) *RepoCommits { rc := new(RepoCommits) rc.Config = config diff --git a/config.go b/config.go index cae70a0..e2e47de 100644 --- a/config.go +++ b/config.go @@ -1,7 +1,7 @@ package main type configCollect struct { - Commits bool `docopt:"commits"` + Head bool `docopt:"head"` Storage string `docopt:"--storage"` RepoId string `docopt:""` } diff --git a/seafile_recovery.go b/seafile_recovery.go index ebbbf8e..d498426 100644 --- a/seafile_recovery.go +++ b/seafile_recovery.go @@ -9,7 +9,7 @@ func main() { usage := `Seafile Recovery. Usage: - seafile_recovery [--storage=] commits + seafile_recovery [--storage=] head seafile_recovery (-h | --help) Options: @@ -24,9 +24,9 @@ Options: checkRootFolder(config.Storage) rexists := repoExistsIn(config.Storage, config.RepoId) - if config.Commits { + if config.Head { if !rexists["commits"] { log.Fatal("No commits folder found for repo ",config.RepoId) } - cmdCommit(config) + cmdHead(config) } else { log.Fatal("This command is not implemented") }