Skip to content

Commit

Permalink
refactor: expose logger for advanced config; omit EDITOR logs by defa…
Browse files Browse the repository at this point in the history
…ult (#6)

* refactor: move logger to separate module & add func to customize it
* chore: omit EDITOR logs by default + tidying
---------

Signed-off-by: Tyler Gillson <tyler.gillson@gmail.com>
  • Loading branch information
TylerGillson authored Jul 15, 2024
1 parent 66ae32c commit ec46421
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
7 changes: 4 additions & 3 deletions prompts/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ func init() {
editor := os.Getenv("EDITOR")
if visual != "" {
editorBinary = visual
logger.Info(fmt.Sprintf("Detected VISUAL env var. Overrode default editor (vi) with %s.", editorBinary))
logger.Debug(fmt.Sprintf("Detected VISUAL env var. Overrode default editor (vi) with %s.", editorBinary))
} else if editor != "" {
editorBinary = editor
logger.Info(fmt.Sprintf("Detected EDITOR env var. Overrode default editor (vi) with %s.", editorBinary))
logger.Debug(fmt.Sprintf("Detected EDITOR env var. Overrode default editor (vi) with %s.", editorBinary))
}
var err error
editorPath, err = exec.LookPath(editorBinary)
Expand All @@ -44,8 +44,9 @@ func getEditorExecutor(editor, filename string) mocks.CommandExecutor {
return cmd
}

// EditFile prompts a user to edit a file with a predefined prompt and initial content.
func EditFile(initialContent []byte) ([]byte, error) {
tmpFile, err := os.CreateTemp(os.TempDir(), "validator")
tmpFile, err := os.CreateTemp(os.TempDir(), "prompts")
if err != nil {
return nil, err
}
Expand Down
10 changes: 10 additions & 0 deletions prompts/logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package prompts

import "github.com/pterm/pterm"

var logger = pterm.DefaultLogger

// SetLogger sets the logger to be used by the prompts package.
func SetLogger(l pterm.Logger) {
logger = l
}
2 changes: 0 additions & 2 deletions prompts/prompts.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ const (
)

var (
logger = pterm.DefaultLogger

// Exported to enable monkey-patching
Tui TUI = PtermTUI{}

Expand Down

0 comments on commit ec46421

Please sign in to comment.