Refactor command organization

This commit is contained in:
Quentin 2021-04-22 11:29:04 +02:00
parent 68795d1f38
commit 0844490d79
Signed by: quentin
GPG Key ID: A98E9B769E4FF428
4 changed files with 24 additions and 19 deletions

20
command.go Normal file
View File

@ -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())
}

View File

@ -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

View File

@ -1,7 +1,7 @@
package main
type configCollect struct {
Commits bool `docopt:"commits"`
Head bool `docopt:"head"`
Storage string `docopt:"--storage"`
RepoId string `docopt:"<repoid>"`
}

View File

@ -9,7 +9,7 @@ func main() {
usage := `Seafile Recovery.
Usage:
seafile_recovery [--storage=<sto>] commits <repoid>
seafile_recovery [--storage=<sto>] head <repoid>
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")
}