Skip to content

Commit

Permalink
Merge pull request #23 from sev-2/feature/logger-verbosity
Browse files Browse the repository at this point in the history
Feature : logger verbosity
  • Loading branch information
toopay authored May 17, 2024
2 parents 75782fa + 47bc264 commit c5e0a8a
Show file tree
Hide file tree
Showing 106 changed files with 5,635 additions and 3,312 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ Available Commands:
version Show application information
Flags:
-h, --help help for raiden
-v, --verbose enable verbose output
--debug enable log with debug mode
-h, --help help for raiden
--trace enable log with trace mode
Use "raiden [command] --help" for more information about a command.
```

## Documentation
For detailed documentation, including security practices and schema management, visit [sev-2.com].
For detailed documentation, including security practices and schema management, visit [raiden.sev-2.com](https://raiden.sev-2.com).

## Contributing
Contributions are welcome! Please read our [Contributing Guidelines](CONTRIBUTING.md) for more information.
Expand Down
20 changes: 10 additions & 10 deletions cmd/raiden/commands/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import (
"github.com/sev-2/raiden/pkg/cli/apply"
"github.com/sev-2/raiden/pkg/cli/configure"
"github.com/sev-2/raiden/pkg/cli/generate"
"github.com/sev-2/raiden/pkg/logger"
"github.com/sev-2/raiden/pkg/utils"
"github.com/spf13/cobra"
)

type ApplyFlags struct {
cli.Flags
cli.LogFlags
Apply apply.Flags
Generate generate.Flags
}
Expand All @@ -24,35 +23,36 @@ func ApplyCommand() *cobra.Command {
Use: "apply",
Short: "Apply resource to supabase",
Long: "Apply model, role, rpc and rls to supabase",
PreRun: PreRun(&f.Flags, apply.PreRun),
PreRun: PreRun(&f.LogFlags, apply.PreRun),
Run: func(cmd *cobra.Command, args []string) {
verbose := f.CheckAndActivateDebug(cmd)
f.CheckAndActivateDebug(cmd)

// get current directory
currentDir, errCurDir := utils.GetCurrentDirectory()
if errCurDir != nil {
logger.Error(errCurDir)
apply.ApplyLogger.Error(errCurDir.Error())
return
}

// load config
apply.ApplyLogger.Info("load configuration")
configFilePath := configure.GetConfigFilePath(currentDir)
logger.Debug("Load configuration from : ", configFilePath)
apply.ApplyLogger.Debug("config file information", "path", configFilePath)
config, err := raiden.LoadConfig(&configFilePath)
if err != nil {
logger.Error(err)
apply.ApplyLogger.Error(err.Error())
return
}

// 1. generate all resource
if err = generate.Run(&f.Generate, config, currentDir, false); err != nil {
logger.Error(err)
apply.ApplyLogger.Error(err.Error())
return
}

// 2. run import
if err = apply.Run(&f.Apply, currentDir, verbose); err != nil {
logger.Error(err)
if err = apply.Run(&f.LogFlags, &f.Apply, currentDir); err != nil {
apply.ApplyLogger.Error(err.Error())
}
},
}
Expand Down
16 changes: 8 additions & 8 deletions cmd/raiden/commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import (
"github.com/sev-2/raiden/pkg/cli/build"
"github.com/sev-2/raiden/pkg/cli/configure"
"github.com/sev-2/raiden/pkg/cli/generate"
"github.com/sev-2/raiden/pkg/logger"
"github.com/sev-2/raiden/pkg/utils"
"github.com/spf13/cobra"
)

type BuildFlags struct {
cli.Flags
cli.LogFlags
Build build.Flags
Generate generate.Flags
}
Expand All @@ -24,36 +23,37 @@ func BuildCommand() *cobra.Command {
Use: "build",
Short: "Build app binary",
Long: "Build app binary base on configuration",
PreRun: PreRun(&f.Flags, build.PreRun),
PreRun: PreRun(&f.LogFlags, build.PreRun),
Run: func(cmd *cobra.Command, args []string) {
f.CheckAndActivateDebug(cmd)

// Preparation
// - get current directory
currentDir, errCurDir := utils.GetCurrentDirectory()
if errCurDir != nil {
logger.Error(errCurDir)
build.BuildLogger.Error(errCurDir.Error())
return
}

// - load config
build.BuildLogger.Info("Load configuration")
configFilePath := configure.GetConfigFilePath(currentDir)
logger.Debug("Load configuration from : ", configFilePath)
build.BuildLogger.Debug("config file information", "path", configFilePath)
config, err := raiden.LoadConfig(&configFilePath)
if err != nil {
logger.Error(err)
build.BuildLogger.Error(err.Error())
return
}

// 1. generate
if err := generate.Run(&f.Generate, config, currentDir, false); err != nil {
logger.Error(err)
build.BuildLogger.Error(err.Error())
return
}

// 2. build app
if err := build.Run(&f.Build, config, currentDir); err != nil {
logger.Error(err)
build.BuildLogger.Error(err.Error())
}
},
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/raiden/commands/command.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
package commands

import (
"github.com/hashicorp/go-hclog"
"github.com/sev-2/raiden/pkg/cli"
"github.com/sev-2/raiden/pkg/logger"
"github.com/sev-2/raiden/pkg/utils"
"github.com/spf13/cobra"
)

func PreRun(f *cli.Flags, callbacks ...func(path string) error) func(*cobra.Command, []string) {
func PreRun(f *cli.LogFlags, callbacks ...func(path string) error) func(*cobra.Command, []string) {
return func(cmd *cobra.Command, args []string) {
f.Bind(cmd)

// get current directory
currentDir, errCurDir := utils.GetCurrentDirectory()
if errCurDir != nil {
logger.Error(errCurDir)
hclog.Default().Error(errCurDir.Error())
return
}

for i := range callbacks {
c := callbacks[i]
if err := c(currentDir); err != nil {
logger.Error(errCurDir)
hclog.Default().Error(err.Error())
return
}
}
Expand Down
9 changes: 4 additions & 5 deletions cmd/raiden/commands/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package commands
import (
"github.com/sev-2/raiden/pkg/cli"
"github.com/sev-2/raiden/pkg/cli/configure"
"github.com/sev-2/raiden/pkg/logger"
"github.com/sev-2/raiden/pkg/utils"
"github.com/spf13/cobra"
)
Expand All @@ -14,7 +13,7 @@ import (
// `Configure` of type `configure.Flags`, which holds the specific flags and options for the
// `configure` command.
type ConfigureFlags struct {
cli.Flags
cli.LogFlags
Configure configure.Flags
}

Expand All @@ -31,18 +30,18 @@ func ConfigureCommand() *cobra.Command {
// get current directory
currentDir, errCurDir := utils.GetCurrentDirectory()
if errCurDir != nil {
logger.Error(errCurDir)
configure.ConfigureLogger.Error(errCurDir.Error())
return
}

config, err := configure.Run(&f.Configure, currentDir)
if err != nil {
logger.Error(err)
configure.ConfigureLogger.Error(err.Error())
return
}

if err = configure.Generate(&config.Config, currentDir); err != nil {
logger.Error(err)
configure.ConfigureLogger.Error(err.Error())
}
},
}
Expand Down
14 changes: 7 additions & 7 deletions cmd/raiden/commands/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import (
"github.com/sev-2/raiden/pkg/cli"
"github.com/sev-2/raiden/pkg/cli/configure"
"github.com/sev-2/raiden/pkg/cli/generate"
"github.com/sev-2/raiden/pkg/logger"
"github.com/sev-2/raiden/pkg/utils"
"github.com/spf13/cobra"
)

type GenerateFlags struct {
cli.Flags
cli.LogFlags
Generate generate.Flags
}

Expand All @@ -22,28 +21,29 @@ func GenerateCommand() *cobra.Command {
Use: "generate",
Short: "Generate application resource",
Long: "Generate route and rpc configuration",
PreRun: PreRun(&f.Flags, generate.PreRun),
PreRun: PreRun(&f.LogFlags, generate.PreRun),
Run: func(cmd *cobra.Command, args []string) {
f.CheckAndActivateDebug(cmd)

// get current directory
currentDir, errCurDir := utils.GetCurrentDirectory()
if errCurDir != nil {
logger.Error(errCurDir)
generate.GenerateLogger.Error(errCurDir.Error())
return
}

// load config
generate.GenerateLogger.Info("Load configuration")
configFilePath := configure.GetConfigFilePath(currentDir)
logger.Debug("Load configuration from : ", configFilePath)
generate.GenerateLogger.Debug("config file information", "path", configFilePath)
config, err := raiden.LoadConfig(&configFilePath)
if err != nil {
logger.Error(err)
generate.GenerateLogger.Error(err.Error())
return
}

if err = generate.Run(&f.Generate, config, currentDir, false); err != nil {
logger.Error(err)
generate.GenerateLogger.Error(err.Error())
}
},
}
Expand Down
20 changes: 10 additions & 10 deletions cmd/raiden/commands/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import (
"github.com/sev-2/raiden/pkg/cli/configure"
"github.com/sev-2/raiden/pkg/cli/generate"
"github.com/sev-2/raiden/pkg/cli/imports"
"github.com/sev-2/raiden/pkg/logger"
"github.com/sev-2/raiden/pkg/utils"
"github.com/spf13/cobra"
)

type ImportsFlags struct {
cli.Flags
cli.LogFlags
Imports imports.Flags
Generate generate.Flags
}
Expand All @@ -24,35 +23,36 @@ func ImportCommand() *cobra.Command {
Use: "imports",
Short: "Import supabase resource",
Long: "Fetch supabase resource and generate to file",
PreRun: PreRun(&f.Flags, imports.PreRun),
PreRun: PreRun(&f.LogFlags, imports.PreRun),
Run: func(cmd *cobra.Command, args []string) {
verbose := f.CheckAndActivateDebug(cmd)
f.CheckAndActivateDebug(cmd)

// get current directory
currentDir, errCurDir := utils.GetCurrentDirectory()
if errCurDir != nil {
logger.Error(errCurDir)
imports.ImportLogger.Error(errCurDir.Error())
return
}

// load config
imports.ImportLogger.Info("Load configuration")
configFilePath := configure.GetConfigFilePath(currentDir)
logger.Debug("Load configuration from : ", configFilePath)
imports.ImportLogger.Debug("config file information", "path", configFilePath)
config, err := raiden.LoadConfig(&configFilePath)
if err != nil {
logger.Error(err)
imports.ImportLogger.Error(err.Error())
return
}

// 1. generate all resource
if err = generate.Run(&f.Generate, config, currentDir, false); err != nil {
logger.Error(err)
imports.ImportLogger.Error(err.Error())
return
}

// 2. run import
if err = imports.Run(&f.Imports, currentDir, verbose); err != nil {
logger.Error(err)
if err = imports.Run(&f.LogFlags, &f.Imports, currentDir); err != nil {
imports.ImportLogger.Error(err.Error())
return
}
},
Expand Down
14 changes: 7 additions & 7 deletions cmd/raiden/commands/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import (
"github.com/sev-2/raiden/pkg/cli"
"github.com/sev-2/raiden/pkg/cli/configure"
init_cmd "github.com/sev-2/raiden/pkg/cli/init"
"github.com/sev-2/raiden/pkg/logger"
"github.com/sev-2/raiden/pkg/utils"
"github.com/spf13/cobra"
)

type InitFlags struct {
cli.Flags
cli.LogFlags
Init init_cmd.Flags
}

Expand All @@ -22,28 +21,29 @@ func InitCommand() *cobra.Command {
Use: "init",
Short: "Init golang app",
Long: "Initialize golang app with install raiden dependency",
PreRun: PreRun(&f.Flags, init_cmd.PreRun),
PreRun: PreRun(&f.LogFlags, init_cmd.PreRun),
Run: func(cmd *cobra.Command, args []string) {
f.CheckAndActivateDebug(cmd)

// get current directory
currentDir, errCurDir := utils.GetCurrentDirectory()
if errCurDir != nil {
logger.Error(errCurDir)
init_cmd.InitLogger.Error(errCurDir.Error())
return
}

// load config
init_cmd.InitLogger.Info("Load configuration")
configFilePath := configure.GetConfigFilePath(currentDir)
logger.Debug("Load configuration from : ", configFilePath)
init_cmd.InitLogger.Debug("config file information", "path", configFilePath)
config, err := raiden.LoadConfig(&configFilePath)
if err != nil {
logger.Error(err)
init_cmd.InitLogger.Error(err.Error())
return
}

if err = init_cmd.Run(&f.Init, currentDir, utils.ToGoModuleName(config.ProjectName)); err != nil {
logger.Error(err)
init_cmd.InitLogger.Error(err.Error())
}
},
}
Expand Down
Loading

0 comments on commit c5e0a8a

Please sign in to comment.