Add reindex cli command
parent
7d1f98a5b8
commit
ac9a485ca2
30
cmd/admin.go
30
cmd/admin.go
|
@ -21,6 +21,7 @@ var (
|
|||
to make automatic initialization process more smoothly`,
|
||||
Subcommands: []cli.Command{
|
||||
subcmdCreateUser,
|
||||
subcmdReindex,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -36,6 +37,16 @@ to make automatic initialization process more smoothly`,
|
|||
stringFlag("config, c", "custom/conf/app.ini", "Custom configuration file path"),
|
||||
},
|
||||
}
|
||||
|
||||
subcmdReindex = cli.Command{
|
||||
Name: "reindex",
|
||||
Usage: "Reindex repository",
|
||||
Action: runReindex,
|
||||
Flags: []cli.Flag{
|
||||
stringFlag("owner", "", "Repository owner"),
|
||||
stringFlag("repo", "", "Repository name"),
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func runCreateUser(c *cli.Context) error {
|
||||
|
@ -68,3 +79,22 @@ func runCreateUser(c *cli.Context) error {
|
|||
fmt.Printf("New user '%s' has been successfully created!\n", c.String("name"))
|
||||
return nil
|
||||
}
|
||||
|
||||
func runReindex(c *cli.Context) error {
|
||||
if !c.IsSet("owner") {
|
||||
return fmt.Errorf("Owner is not specified")
|
||||
} else if !c.IsSet("repo") {
|
||||
return fmt.Errorf("Repository is not specified")
|
||||
}
|
||||
|
||||
setting.NewContext()
|
||||
models.LoadConfigs()
|
||||
models.SetEngine()
|
||||
|
||||
if err := models.ReindexCommits(c.String("owner"), c.String("repo")); err != nil {
|
||||
return fmt.Errorf("ReindexRepository: %v", err)
|
||||
}
|
||||
|
||||
fmt.Printf("Repository %s/%s reindexed\n", c.String("owner"), c.String("repo"))
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue