Skip to content

Commit

Permalink
fix transform log breaking on log fn pass-in
Browse files Browse the repository at this point in the history
Signed-off-by: Kit Patella <[email protected]>
  • Loading branch information
mkcp committed Oct 30, 2024
1 parent 71eae1c commit d7b2f0d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ var devTransformGitLinksCmd = &cobra.Command{
Aliases: []string{"p"},
Short: lang.CmdDevPatchGitShort,
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, args []string) error {
host, fileName := args[0], args[1]
ctx := cmd.Context()

// Read the contents of the given file
content, err := os.ReadFile(fileName)
Expand All @@ -121,16 +120,11 @@ var devTransformGitLinksCmd = &cobra.Command{
// Perform git url transformation via regex
text := string(content)

// Set log func for transform
var logFn func(string, ...any)
logFn = message.Warnf
// Use logger if we can
if logger.Enabled(ctx) {
logFn = logger.From(ctx).Warn
}
processedText := transform.MutateGitURLsInText(logFn, gitServer.Address, text, gitServer.PushUsername)
// TODO(mkcp): Currently uses message for its log fn. Migrate to ctx and slog
processedText := transform.MutateGitURLsInText(message.Warnf, gitServer.Address, text, gitServer.PushUsername)

// Print the differences
// TODO(mkcp): Uses pterm to print text diffs. Decouple from pterm after we release logger.
dmp := diffmatchpatch.New()
diffs := dmp.DiffMain(text, processedText, true)
diffs = dmp.DiffCleanupSemantic(diffs)
Expand Down
1 change: 1 addition & 0 deletions src/pkg/transform/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
package transform

// Log is a function that logs a message.
// TODO(mkcp): Remove Log and port over to logger once we remove message.
type Log func(string, ...any)

0 comments on commit d7b2f0d

Please sign in to comment.