Refactor command organization
This commit is contained in:
parent
68795d1f38
commit
0844490d79
4 changed files with 24 additions and 19 deletions
20
command.go
Normal file
20
command.go
Normal 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())
|
||||||
|
}
|
15
commit.go
15
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)
|
`, *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 {
|
func NewRepoCommits (config configCollect) *RepoCommits {
|
||||||
rc := new(RepoCommits)
|
rc := new(RepoCommits)
|
||||||
rc.Config = config
|
rc.Config = config
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
type configCollect struct {
|
type configCollect struct {
|
||||||
Commits bool `docopt:"commits"`
|
Head bool `docopt:"head"`
|
||||||
Storage string `docopt:"--storage"`
|
Storage string `docopt:"--storage"`
|
||||||
RepoId string `docopt:"<repoid>"`
|
RepoId string `docopt:"<repoid>"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ func main() {
|
||||||
usage := `Seafile Recovery.
|
usage := `Seafile Recovery.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
seafile_recovery [--storage=<sto>] commits <repoid>
|
seafile_recovery [--storage=<sto>] head <repoid>
|
||||||
seafile_recovery (-h | --help)
|
seafile_recovery (-h | --help)
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
|
@ -24,9 +24,9 @@ Options:
|
||||||
checkRootFolder(config.Storage)
|
checkRootFolder(config.Storage)
|
||||||
rexists := repoExistsIn(config.Storage, config.RepoId)
|
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) }
|
if !rexists["commits"] { log.Fatal("No commits folder found for repo ",config.RepoId) }
|
||||||
cmdCommit(config)
|
cmdHead(config)
|
||||||
} else {
|
} else {
|
||||||
log.Fatal("This command is not implemented")
|
log.Fatal("This command is not implemented")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue