fix(config): correctly set config flag
Some checks are pending
Code QL / code-ql (push) Waiting to run
Release / changelog (push) Waiting to run
Release / artifacts (push) Blocked by required conditions

resolves #5882
This commit is contained in:
Jan De Dobbeleer 2024-11-13 23:45:47 +01:00 committed by Jan De Dobbeleer
parent 9349de4998
commit b21c2d2c71
9 changed files with 26 additions and 18 deletions

View file

@ -40,7 +40,8 @@ Exports the current config to "~/new_config.omp.json" (in JSON format).`,
os.Exit(2)
}
cfg := config.Load(configFlag, shell.GENERIC, false)
configFile := config.Path(configFlag)
cfg := config.Load(configFile, shell.GENERIC, false)
validateExportFormat := func() {
format = strings.ToLower(format)

View file

@ -50,10 +50,11 @@ Exports the config to an image file ~/mytheme.png.
Exports the config to an image file using customized output options.`,
Args: cobra.NoArgs,
Run: func(_ *cobra.Command, _ []string) {
cfg := config.Load(configFlag, shell.GENERIC, false)
configFile := config.Path(configFlag)
cfg := config.Load(configFile, shell.GENERIC, false)
flags := &runtime.Flags{
Config: configFlag,
Config: configFile,
Shell: shell.GENERIC,
TerminalWidth: 150,
}

View file

@ -40,10 +40,11 @@ Migrates the ~/myconfig.omp.json config file to TOML and writes the result to yo
A backup of the current config can be found at ~/myconfig.omp.json.bak.`,
Args: cobra.NoArgs,
Run: func(_ *cobra.Command, _ []string) {
cfg := config.Load(configFlag, shell.GENERIC, true)
configFile := config.Path(configFlag)
cfg := config.Load(configFile, shell.GENERIC, true)
flags := &runtime.Flags{
Config: configFlag,
Config: configFile,
Migrate: true,
}

View file

@ -35,10 +35,11 @@ Migrates the ~/myconfig.omp.json config file's glyphs and writes the result to y
A backup of the current config can be found at ~/myconfig.omp.json.bak.`,
Args: cobra.NoArgs,
Run: func(_ *cobra.Command, _ []string) {
cfg := config.Load(configFlag, shell.GENERIC, false)
configFile := config.Path(configFlag)
cfg := config.Load(configFile, shell.GENERIC, false)
flags := &runtime.Flags{
Config: configFlag,
Config: configFile,
}
env := &runtime.Terminal{}

View file

@ -6,6 +6,7 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/build"
"github.com/jandedobbeleer/oh-my-posh/src/config"
"github.com/jandedobbeleer/oh-my-posh/src/log"
"github.com/jandedobbeleer/oh-my-posh/src/prompt"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
"github.com/jandedobbeleer/oh-my-posh/src/template"
@ -36,10 +37,14 @@ func createDebugCmd() *cobra.Command {
return
}
cfg := config.Load(configFlag, args[0], false)
log.Enable()
log.Debug("debug mode enabled")
configFile := config.Path(configFlag)
cfg := config.Load(configFile, args[0], false)
flags := &runtime.Flags{
Config: configFlag,
Config: configFile,
Debug: true,
PWD: pwd,
Shell: args[0],

View file

@ -5,6 +5,7 @@ import (
"time"
"github.com/jandedobbeleer/oh-my-posh/src/config"
"github.com/jandedobbeleer/oh-my-posh/src/log"
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
"github.com/jandedobbeleer/oh-my-posh/src/shell"
"github.com/jandedobbeleer/oh-my-posh/src/template"
@ -66,15 +67,19 @@ See the documentation to initialize your shell: https://ohmyposh.dev/docs/instal
func runInit(sh string) {
var startTime time.Time
if debug {
startTime = time.Now()
log.Enable()
log.Debug("debug mode enabled")
}
cfg := config.Load(configFlag, sh, false)
configFile := config.Path(configFlag)
cfg := config.Load(configFile, sh, false)
flags := &runtime.Flags{
Shell: sh,
Config: configFlag,
Config: configFile,
Strict: strict,
Debug: debug,
}

View file

@ -25,8 +25,6 @@ import (
func Load(configFile, sh string, migrate bool) *Config {
defer log.Trace(time.Now())
configFile = Path(configFile)
cfg := loadConfig(configFile)
// only migrate automatically when the switch isn't set

View file

@ -462,6 +462,7 @@ func (e *Engine) rectifyTerminalWidth(diff int) {
// given configuration options, and is ready to print any
// of the prompt components.
func New(flags *runtime.Flags) *Engine {
flags.Config = config.Path(flags.Config)
cfg := config.Load(flags.Config, flags.Shell, flags.Migrate)
env := &runtime.Terminal{}

View file

@ -49,11 +49,6 @@ func (term *Terminal) Init(flags *Flags) {
term.CmdFlags = &Flags{}
}
if term.CmdFlags.Debug {
log.Enable()
log.Debug("debug mode enabled")
}
if term.CmdFlags.Plain {
log.Plain()
log.Debug("plain mode enabled")