Align root command with other ocis-extensions

This commit is contained in:
Benedikt Kulmann
2020-06-30 12:50:39 +02:00
parent 52c793b4a0
commit a48334eaad

View File

@@ -2,13 +2,10 @@ package command
import (
"os"
"os/user"
"path"
"strings"
"github.com/owncloud/ocis-accounts/pkg/flagset"
"github.com/joho/godotenv"
"github.com/micro/cli/v2"
"github.com/owncloud/ocis-accounts/pkg/config"
"github.com/owncloud/ocis-accounts/pkg/version"
@@ -27,29 +24,8 @@ func Execute() error {
app := &cli.App{
Name: "ocis-accounts",
Version: version.String,
Usage: "Example service for Reva/oCIS",
Usage: "Provide accounts and groups for oCIS",
Compiled: version.Compiled(),
Flags: flagset.RootWithConfig(cfg),
Before: func(c *cli.Context) error {
err := ParseConfig(c, cfg)
logger := NewLogger(cfg)
for _, v := range defaultConfigPaths {
// location is the user's home
if v[0] == '$' || v[0] == '~' {
usr, _ := user.Current()
err := godotenv.Load(path.Join(usr.HomeDir, ".ocis", defaultFilename+".env"))
if err != nil {
logger.Debug().Msgf("ignoring missing env file on dir: %v", v)
}
} else {
err := godotenv.Load(path.Join(v, defaultFilename+".env"))
if err != nil {
logger.Debug().Msgf("ignoring missing env file on dir: %v", v)
}
}
}
return err
},
Authors: []*cli.Author{
{
@@ -58,6 +34,12 @@ func Execute() error {
},
},
Flags: flagset.RootWithConfig(cfg),
Before: func(c *cli.Context) error {
return ParseConfig(c, cfg)
},
Commands: []*cli.Command{
Server(cfg),
},