mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-09 20:44:03 -08:00
refactor(cli): isolate debug command
This commit is contained in:
parent
34a7d917a8
commit
6e3c1af164
2
.github/ISSUE_TEMPLATE/bug.yml
vendored
2
.github/ISSUE_TEMPLATE/bug.yml
vendored
|
@ -56,7 +56,7 @@ body:
|
|||
id: logs
|
||||
attributes:
|
||||
label: Log output
|
||||
description: Please copy and paste the output generated by `Write-PoshDebug (PowerShell)`, or `oh-my-posh prompt print debug --shell uni --config="$POSH_THEME"` for other shells.
|
||||
description: Please copy and paste the output generated by `Write-PoshDebug (PowerShell)`, or `oh-my-posh prompt debug` for other shells.
|
||||
render: shell
|
||||
validations:
|
||||
required: true
|
||||
|
|
1
.vscode/launch.json
vendored
1
.vscode/launch.json
vendored
|
@ -63,7 +63,6 @@
|
|||
"program": "${workspaceRoot}/src",
|
||||
"args": [
|
||||
"prompt",
|
||||
"print",
|
||||
"debug",
|
||||
"--config=${workspaceRoot}/themes/jandedobbeleer.omp.json"
|
||||
]
|
||||
|
|
59
src/cli/prompt_debug.go
Normal file
59
src/cli/prompt_debug.go
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
|
||||
|
||||
*/
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"oh-my-posh/color"
|
||||
"oh-my-posh/console"
|
||||
"oh-my-posh/engine"
|
||||
"oh-my-posh/environment"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// debugCmd represents the prompt command
|
||||
var debugCmd = &cobra.Command{
|
||||
Use: "debug",
|
||||
Short: "Print the prompt in debug mode",
|
||||
Long: "Print the prompt in debug mode",
|
||||
Args: cobra.NoArgs,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
env := &environment.ShellEnvironment{
|
||||
CmdFlags: &environment.Flags{
|
||||
Config: config,
|
||||
},
|
||||
}
|
||||
env.Init(true)
|
||||
defer env.Close()
|
||||
cfg := engine.LoadConfig(env)
|
||||
ansi := &color.Ansi{}
|
||||
ansi.Init("shell")
|
||||
writerColors := cfg.MakeColors(env)
|
||||
writer := &color.AnsiWriter{
|
||||
Ansi: ansi,
|
||||
TerminalBackground: engine.GetConsoleBackgroundColor(env, cfg.TerminalBackground),
|
||||
AnsiColors: writerColors,
|
||||
}
|
||||
consoleTitle := &console.Title{
|
||||
Env: env,
|
||||
Ansi: ansi,
|
||||
Template: cfg.ConsoleTitleTemplate,
|
||||
}
|
||||
eng := &engine.Engine{
|
||||
Config: cfg,
|
||||
Env: env,
|
||||
Writer: writer,
|
||||
ConsoleTitle: consoleTitle,
|
||||
Ansi: ansi,
|
||||
Plain: plain,
|
||||
}
|
||||
fmt.Print(eng.PrintDebug(cliVersion))
|
||||
},
|
||||
}
|
||||
|
||||
func init() { // nolint:gochecknoinits
|
||||
promptCmd.AddCommand(debugCmd)
|
||||
}
|
|
@ -29,11 +29,10 @@ var (
|
|||
|
||||
// printCmd represents the prompt command
|
||||
var printCmd = &cobra.Command{
|
||||
Use: "print [debug|primary|secondary|transient|right|tooltip|valid|error]",
|
||||
Use: "print [primary|secondary|transient|right|tooltip|valid|error]",
|
||||
Short: "Print the prompt/context",
|
||||
Long: "Print one of the prompts based on the location/use-case.",
|
||||
ValidArgs: []string{
|
||||
"debug",
|
||||
"primary",
|
||||
"secondary",
|
||||
"transient",
|
||||
|
@ -57,16 +56,11 @@ var printCmd = &cobra.Command{
|
|||
Shell: shell,
|
||||
},
|
||||
}
|
||||
debug := args[0] == "debug"
|
||||
env.Init(debug)
|
||||
env.Init(false)
|
||||
defer env.Close()
|
||||
cfg := engine.LoadConfig(env)
|
||||
ansi := &color.Ansi{}
|
||||
shell := env.Shell()
|
||||
if debug {
|
||||
shell = "shell"
|
||||
}
|
||||
ansi.Init(shell)
|
||||
ansi.Init(env.Shell())
|
||||
var writer color.Writer
|
||||
if plain {
|
||||
writer = &color.PlainWriter{}
|
||||
|
@ -92,8 +86,6 @@ var printCmd = &cobra.Command{
|
|||
Plain: plain,
|
||||
}
|
||||
switch args[0] {
|
||||
case "debug":
|
||||
fmt.Print(eng.PrintDebug(cliVersion))
|
||||
case "primary":
|
||||
fmt.Print(eng.PrintPrimary())
|
||||
case "secondary":
|
||||
|
|
|
@ -114,7 +114,7 @@ Set-Item -Path Function:prompt -Value $Prompt -Force
|
|||
function global:Write-PoshDebug {
|
||||
$omp = "::OMP::"
|
||||
$config, $cleanPWD, $cleanPSWD = Get-PoshContext
|
||||
$standardOut = @(&$omp prompt print debug --error=1337 --pwd="$cleanPWD" --pswd="$cleanPSWD" --execution-time=9001 --config="$config" 2>&1)
|
||||
$standardOut = @(&$omp prompt debug --config="$config" 2>&1)
|
||||
$standardOut -join "`n"
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue