Skip to content

Commit

Permalink
refactored get short name function
Browse files Browse the repository at this point in the history
  • Loading branch information
networkop committed Jul 6, 2021
1 parent 4caa86f commit 2d8b6f9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion clab/clab.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func (c *CLab) ListContainers(ctx context.Context, labels []*types.GenericFilter
}

func (c *CLab) GetNodeRuntime(query string) (runtime.ContainerRuntime, error) {
_, _, shortName, err := parseLongName(query)
shortName, err := getShortName(c.Config.Name, query)
if err != nil {
return nil, err
}
Expand Down
11 changes: 6 additions & 5 deletions clab/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,10 +609,11 @@ func sysMemory(v string) uint64 {
return m
}

func parseLongName(input string) (string, string, string, error) {
result := strings.Split(input, "-")
if len(result) != 3 {
return "", "", "", fmt.Errorf("failed to parse container name %q", input)
// returns nodeCfg.ShortName based on the provided containerName and labName
func getShortName(labName, containerName string) (string, error) {
result := strings.Split(containerName, "-"+labName+"-")
if len(result) != 2 {
return "", fmt.Errorf("failed to parse container name %q", containerName)
}
return result[0], result[1], result[2], nil
return result[1], nil
}

0 comments on commit 2d8b6f9

Please sign in to comment.