Skip to content

Commit

Permalink
Change -s logic to include complete profile and parsed config
Browse files Browse the repository at this point in the history
  • Loading branch information
simbados committed Feb 12, 2024
1 parent b22e48a commit 026d8f6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 31 deletions.
14 changes: 5 additions & 9 deletions cmd/sb/sb.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@ func main() {
// set config parameter
setConfigParams(&context, input)

// parse config files
if context.Config.CliConfig == nil {
context.Config.SbConfig = util.ConfigFileParsing(&context)
} else {
log.LogDebug("Using cli options")
context.Config.SbConfig = context.Config.CliConfig
}

// build sandbox profile
minifiedProfile, profile := sandbox.BuildSandboxProfile(&context)

if types.CliOptions.ShowConfigEnabled {
util.ShowConfig(&context.Config, profile)
}

log.LogDebug(log.PrettyJson(&context))

if !types.CliOptions.DryRunEnabled {
Expand Down Expand Up @@ -95,13 +97,7 @@ func checkCliOptions(context *types.Context, commands []string) {
} else if currentOption == "--edit" || currentOption == "-e" {
util.EditFile(commands, &context.Paths)
} else if currentOption == "--show" || currentOption == "-s" {
if len(commands) != 1 {
log.LogErr(`
You need to specify which config files you want to see
E.g. sb -s npm
`)
}
util.ShowConfig(context, commands[0])
types.CliOptions.ShowConfigEnabled = true
} else if currentOption == "--vigilant" || currentOption == "-vi" {
types.CliOptions.VigilantModeEnabled = true
}
Expand Down
1 change: 1 addition & 0 deletions internal/types/cliOptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ type CliOptionsStr struct {
DebugEnabled bool `json:"debug-enabled"`
DryRunEnabled bool `json:"dry-run-enabled"`
CreateExeEnabled bool `json:"create-exe-enabled"`
ShowConfigEnabled bool `json:"show-config-enabled"`
HelpEnabled bool `json:"help"`
VersionEnabled bool `json:"version-enabled"`
EditEnabled bool `json:"edit-enabled"`
Expand Down
2 changes: 1 addition & 1 deletion internal/util/parseConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func doesRootConfigExists(context *types.Context) (string, bool) {
binaryGlobalConfigPath := context.Paths.RootConfigPath + "/" + context.Config.BinaryName + ".json"
binaryPathExists, _ := DoesPathExist(binaryGlobalConfigPath)
if !binaryPathExists {
log.LogWarn("No config for binary found. You might want to create a config file at: ", context.Paths.RootConfigPath)
log.LogDebug("No root config for binary found. You might want to create a config file at: ", context.Paths.RootConfigPath)
} else {
log.LogDebug("Using global config file")
return binaryGlobalConfigPath, true
Expand Down
26 changes: 5 additions & 21 deletions internal/util/show.go
Original file line number Diff line number Diff line change
@@ -1,31 +1,15 @@
package util

import (
"fmt"
"os"
"path/filepath"
"sb/internal/log"
"sb/internal/types"
)

func ShowConfig(context *types.Context, binaryName string) {
localConfigPath, exists := LocalConfigPath(&context.Paths, binaryName)
if !exists {
log.LogInfoLn("Local Config not found, trying root config")
path := filepath.Join(context.Paths.RootConfigPath, binaryName+".json")
configExists, err := DoesPathExist(path)
if err != nil {
log.LogErr(err)
}
if configExists {
log.LogHighlight(fmt.Sprintf("Root config found at path %v", path))
configJson := ParseJson(path)
log.LogInfoLn(log.PrettyJson(configJson))
}
} else {
log.LogHighlight(fmt.Sprintf("Local config found at path %v", localConfigPath))
configJson := ParseJson(localConfigPath)
log.LogInfoLn(log.PrettyJson(configJson))
}
func ShowConfig(config *types.Config, profile string) {
log.LogHighlight("\nSandbox profile which will be applied\n")
log.LogInfoLn(profile)
log.LogHighlight("\nConfig parsed from config files: \n")
log.LogInfoLn(log.PrettyJson(config.SbConfig))
os.Exit(0)
}

0 comments on commit 026d8f6

Please sign in to comment.