refactor: use app getting instead of boilerplate

This commit is contained in:
2021-09-05 23:17:35 +02:00
parent 48bcc9cb36
commit d4333c2dc0
18 changed files with 111 additions and 266 deletions

View File

@ -31,23 +31,13 @@ var appRestoreCommand = &cli.Command{
Flags: []cli.Flag{restoreAllServicesFlag},
ArgsUsage: "<service> [<backup file>]",
Action: func(c *cli.Context) error {
appName := internal.ValidateAppNameArg(c)
app := internal.ValidateApp(c)
if c.Args().Len() > 1 && restoreAllServices {
internal.ShowSubcommandHelpAndError(c, errors.New("cannot use <service>/<backup file> and '--all' together"))
}
appFiles, err := config.LoadAppFiles("")
if err != nil {
logrus.Fatal(err)
}
appEnv, err := config.GetApp(appFiles, appName)
if err != nil {
logrus.Fatal(err)
}
abraSh := path.Join(config.ABRA_DIR, "apps", appEnv.Type, "abra.sh")
abraSh := path.Join(config.ABRA_DIR, "apps", app.Type, "abra.sh")
if _, err := os.Stat(abraSh); err != nil {
if os.IsNotExist(err) {
logrus.Fatalf("'%s' does not exist?", abraSh)
@ -70,7 +60,7 @@ var appRestoreCommand = &cli.Command{
logrus.Fatal(err)
}
if !strings.Contains(string(bytes), execCmd) {
logrus.Fatalf("%s doesn't have a '%s' function", appEnv.Type, execCmd)
logrus.Fatalf("%s doesn't have a '%s' function", app.Type, execCmd)
}
backupFile := c.Args().Get(2)