Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor changes #223

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions adapter/socketclient/socketclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func (c *Client) Connect() error {
return err
}

if err := c.open(); err != nil {
if err := c.open(c.clientName); err != nil {
_ = c.disconnect()
return err
}
Expand Down Expand Up @@ -353,12 +353,12 @@ const (
deleteMsgContext = byte(124)
)

func (c *Client) open() error {
func (c *Client) open(clientName string) error {
var msgCodec = codec.DefaultCodec

// Request socket client create
req := &memclnt.SockclntCreate{
Name: c.clientName,
Name: clientName,
}
msg, err := msgCodec.EncodeMsg(req, sockCreateMsgId)
if err != nil {
Expand Down Expand Up @@ -540,6 +540,7 @@ func (c *Client) readerLoop() {
msg, err := c.readMsg(buf[:])
if err != nil {
if isClosedError(err) {
log.Debugf("reader closed: %v", err)
return
}
log.Debugf("readMsg error: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion binapigen/vppapi/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func cloneRepoLocally(repo string, commit string, branch string, depth int) (str
} else if err != nil {
return "", fmt.Errorf("failed to check if cache exists: %w", err)
}
logrus.Debugf("local repo dir: %q, fetching %q", cachePath, commit)
logrus.Debugf("using local repo dir: %q, fetching %q", cachePath, commit)

cmd := exec.Command("git", "fetch", "--tags", "origin")
cmd.Dir = cachePath
Expand Down
4 changes: 1 addition & 3 deletions cmd/govpp/cmd_vppapi_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
"github.com/olekukonko/tablewriter"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"go.fd.io/govpp/binapigen/vppapi"
)

// TODO:
Expand Down Expand Up @@ -103,7 +101,7 @@ func runVppApiDiffCmd(out io.Writer, opts VppApiDiffCmdOptions) error {
return err
}

vppAgainst, err := vppapi.ResolveVppInput(opts.Against)
vppAgainst, err := resolveVppInput(opts.Against)
if err != nil {
return fmt.Errorf("resolving --against failed: %w", err)
}
Expand Down
30 changes: 15 additions & 15 deletions cmd/govpp/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func CompareSchemas(schema1, schema2 *vppapi.Schema) []Difference {
differences = append(differences, Difference{
Type: VersionDifference,
Description: color.Sprintf("Schema version is different: %s vs %s",
clrWhite.Sprint(schema1.Version), clrWhite.Sprint(schema2.Version)),
clrDiffVersion.Sprint(schema1.Version), clrDiffVersion.Sprint(schema2.Version)),
Value1: schema1.Version,
Value2: schema2.Version,
})
Expand All @@ -126,7 +126,7 @@ func CompareSchemas(schema1, schema2 *vppapi.Schema) []Difference {
Type: TotalFilesDifference,
Description: color.Sprintf("Total file count %s from %v to %v",
clrWhite.Sprint(numberChangeString(len(schema1.Files), len(schema2.Files))),
clrWhite.Sprint(len(schema1.Files)), clrWhite.Sprint(len(schema2.Files))),
clrDiffNumber.Sprint(len(schema1.Files)), clrDiffNumber.Sprint(len(schema2.Files))),
Value1: len(schema1.Files),
Value2: len(schema2.Files),
})
Expand Down Expand Up @@ -169,7 +169,7 @@ func compareSchemaFiles(files1 []vppapi.File, files2 []vppapi.File) []Difference
} else {
differences = append(differences, Difference{
Type: FileRemovedDifference,
Description: color.Sprintf("File removed: %s", clrWhite.Sprint(fileName)),
Description: color.Sprintf("File removed: %s", clrDiffFile.Sprint(fileName)),
Value1: file1,
Value2: nil,
})
Expand All @@ -181,7 +181,7 @@ func compareSchemaFiles(files1 []vppapi.File, files2 []vppapi.File) []Difference
if _, ok := fileMap1[fileName]; !ok {
differences = append(differences, Difference{
Type: FileAddedDifference,
Description: color.Sprintf("File added: %s", clrWhite.Sprint(fileName)),
Description: color.Sprintf("File added: %s", clrDiffFile.Sprint(fileName)),
Value1: nil,
Value2: file2,
})
Expand Down Expand Up @@ -228,7 +228,7 @@ func compareFiles(file1, file2 vppapi.File) []Difference {
differences = append(differences, Difference{
Type: FileVersionDifference,
Description: color.Sprintf("File version changed from %s to %s",
clrWhite.Sprint(fileVer1), clrWhite.Sprint(fileVer2)),
clrDiffVersion.Sprint(fileVer1), clrDiffVersion.Sprint(fileVer2)),
Value1: fileVer1,
Value2: fileVer2,
})
Expand All @@ -237,7 +237,7 @@ func compareFiles(file1, file2 vppapi.File) []Difference {
differences = append(differences, Difference{
Type: FileCrcDifference,
Description: color.Sprintf("File CRC changed from %s to %s",
clrWhite.Sprint(file1.CRC), clrWhite.Sprint(file2.CRC)),
clrDiffVersion.Sprint(file1.CRC), clrDiffVersion.Sprint(file2.CRC)),
Value1: file1.CRC,
Value2: file2.CRC,
})
Expand Down Expand Up @@ -289,7 +289,7 @@ func compareFiles(file1, file2 vppapi.File) []Difference {
} else {
differences = append(differences, Difference{
Type: MessageRemovedDifference,
Description: color.Sprintf("Message removed: %s", clrCyan.Sprint(msgName)),
Description: color.Sprintf("Message removed: %s", clrDiffMessage.Sprint(msgName)),
Value1: msg1,
Value2: nil,
})
Expand All @@ -300,7 +300,7 @@ func compareFiles(file1, file2 vppapi.File) []Difference {
if _, ok := msgMap1[msgName]; !ok {
differences = append(differences, Difference{
Type: MessageAddedDifference,
Description: color.Sprintf("Message added: %s", clrCyan.Sprint(msgName)),
Description: color.Sprintf("Message added: %s", clrDiffMessage.Sprint(msgName)),
Value1: nil,
Value2: msg,
})
Expand All @@ -324,15 +324,15 @@ func compareMessages(msg1 vppapi.Message, msg2 vppapi.Message) []Difference {
differences = append(differences, Difference{
Type: MessageCrcDifference,
Description: color.Sprintf("Message %s changed CRC from %s to %s",
clrCyan.Sprint(msg1.Name), clrWhite.Sprint(msg1.CRC), clrWhite.Sprint(msg2.CRC)),
clrDiffMessage.Sprint(msg1.Name), clrDiffVersion.Sprint(msg1.CRC), clrDiffVersion.Sprint(msg2.CRC)),
Value1: msg1.CRC,
Value2: msg2.CRC,
})
}

// Compare message comments
if msg1.Comment != msg2.Comment {
desc := color.Sprintf("Message %s comment ", clrCyan.Sprint(msg1.Name))
desc := color.Sprintf("Message %s comment ", clrDiffMessage.Sprint(msg1.Name))
if msg1.Comment == "" {
desc += "added"
} else if msg2.Comment == "" {
Expand All @@ -355,7 +355,7 @@ func compareMessages(msg1 vppapi.Message, msg2 vppapi.Message) []Difference {
differences = append(differences, Difference{
Type: MsgOptionChangedDifference,
Description: color.Sprintf("Message %s changed option %s from %q to %q",
clrCyan.Sprint(msg1.Name), clrWhite.Sprint(option), clrWhite.Sprint(val1), clrWhite.Sprint(val2)),
clrDiffMessage.Sprint(msg1.Name), clrDiffOption.Sprint(option), clrDiffOption.Sprint(val1), clrDiffOption.Sprint(val2)),
Value1: keyValString(option, val1),
Value2: keyValString(option, val2),
})
Expand All @@ -364,7 +364,7 @@ func compareMessages(msg1 vppapi.Message, msg2 vppapi.Message) []Difference {
differences = append(differences, Difference{
Type: MsgOptionRemovedDifference,
Description: color.Sprintf("Message %s removed option: %s",
clrCyan.Sprint(msg1.Name), clrWhite.Sprint(option)),
clrDiffMessage.Sprint(msg1.Name), clrDiffOption.Sprint(keyValString(option, val1))),
Value1: keyValString(option, val1),
Value2: "",
})
Expand All @@ -376,7 +376,7 @@ func compareMessages(msg1 vppapi.Message, msg2 vppapi.Message) []Difference {
differences = append(differences, Difference{
Type: MsgOptionAddedDifference,
Description: color.Sprintf("Message %s added option: %s",
clrCyan.Sprint(msg2.Name), clrWhite.Sprint(keyValString(option, val2))),
clrDiffMessage.Sprint(msg2.Name), clrDiffOption.Sprint(keyValString(option, val2))),
Value1: "",
Value2: keyValString(option, val2),
})
Expand All @@ -390,7 +390,7 @@ func numberOfContentChangedDifference(typ string, c1, c2 int) Difference {
return Difference{
Type: FileContentsChangedDifference,
Description: color.Sprintf("Number of %s has %s from %v to %v",
clrWhite.Sprint(typ), clrWhite.Sprint(numberChangeString(c1, c2)), clrWhite.Sprint(c1), clrWhite.Sprint(c2)),
clrWhite.Sprint(typ), clrWhite.Sprint(numberChangeString(c1, c2)), clrDiffNumber.Sprint(c1), clrDiffNumber.Sprint(c2)),
Value1: c1,
Value2: c2,
}
Expand All @@ -411,5 +411,5 @@ func keyValString(k, v string) string {
if v == "" {
return k
}
return color.Sprintf("%s=%s", k, v)
return color.Sprintf("%s=%q", k, v)
}
10 changes: 8 additions & 2 deletions cmd/govpp/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package main

import (
"fmt"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -42,8 +43,13 @@ func resolveVppInput(input string) (*vppapi.VppInput, error) {

tookSec := time.Since(t).Seconds()

logrus.Tracef("resolved VPP input %q in %.3fs\n%s\n - API dir: %s\n - VPP Version: %s\n - Files: %v",
input, tookSec, strings.Repeat("-", 100), vppInput.ApiDirectory, vppInput.Schema.Version, len(vppInput.Schema.Files))
logrus.WithFields(map[string]interface{}{
"took": fmt.Sprintf("%.3fs", tookSec),
"version": vppInput.Schema.Version,
"files": len(vppInput.Schema.Files),
"apiDir": len(vppInput.Schema.Files),
}).Tracef("resolved VPP input %q\n%s\n - API dir: %s\n - VPP Version: %s\n - Files: %v",
input, strings.Repeat("-", 100), vppInput.ApiDirectory, vppInput.Schema.Version, len(vppInput.Schema.Files))

return vppInput, nil
}
Expand Down
9 changes: 6 additions & 3 deletions cmd/govpp/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ import (
)

var (
clrWhite = color.Style{color.White}
clrCyan = color.Style{color.Cyan}
clrDiffFile = color.Style{color.Yellow}
clrWhite = color.Style{color.White}
clrDiffMessage = color.Style{color.Cyan}
clrDiffOption = color.Style{color.Blue}
clrDiffFile = color.Style{color.Yellow}
clrDiffVersion = color.Style{color.LightMagenta}
clrDiffNumber = color.Style{color.LightBlue}
)

const (
Expand Down
Loading
Loading