diff --git a/cmd/main.go b/cmd/main.go index 659dfac27..c95dbf62a 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -23,6 +23,7 @@ import ( "github.com/minio/cli" "github.com/minio/mc/pkg/console" "github.com/minio/minio/pkg/trie" + "github.com/minio/minio/pkg/words" ) // global flags for minio. @@ -86,7 +87,7 @@ func newApp() *cli.App { } // 2 is arbitrary and represents the max // allowed number of typed errors - if DamerauLevenshteinDistance(command, value.(string)) < 2 { + if words.DamerauLevenshteinDistance(command, value.(string)) < 2 { closestCommands = append(closestCommands, value.(string)) } } diff --git a/cmd/damerau-levenshtein.go b/pkg/words/damerau-levenshtein.go similarity index 95% rename from cmd/damerau-levenshtein.go rename to pkg/words/damerau-levenshtein.go index 1e275e78b..f8bf1eb12 100644 --- a/cmd/damerau-levenshtein.go +++ b/pkg/words/damerau-levenshtein.go @@ -1,5 +1,5 @@ /* - * Minio Client (C) 2014-2016 Minio, Inc. + * Minio Client (C) 2014, 2015, 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,9 @@ * limitations under the License. */ -package cmd +package words -import ( - "math" -) +import "math" // Returns the minimum value of a slice of integers func minimum(integers []int) (minVal int) { @@ -34,6 +32,7 @@ func minimum(integers []int) (minVal int) { // DamerauLevenshteinDistance calculates distance between two strings using an algorithm // described in https://en.wikipedia.org/wiki/Damerau-Levenshtein_distance func DamerauLevenshteinDistance(a string, b string) int { + var cost int d := make([][]int, len(a)+1) for i := 1; i <= len(a)+1; i++ { d[i-1] = make([]int, len(b)+1) @@ -44,7 +43,6 @@ func DamerauLevenshteinDistance(a string, b string) int { for j := 0; j <= len(b); j++ { d[0][j] = j } - var cost int for i := 1; i <= len(a); i++ { for j := 1; j <= len(b); j++ { if a[i-1] == b[j-1] { diff --git a/cmd/damerau-levenshtein_test.go b/pkg/words/damerau-levenshtein_test.go similarity index 96% rename from cmd/damerau-levenshtein_test.go rename to pkg/words/damerau-levenshtein_test.go index fccec4405..62c64a338 100644 --- a/cmd/damerau-levenshtein_test.go +++ b/pkg/words/damerau-levenshtein_test.go @@ -1,5 +1,5 @@ /* - * Minio Cloud Storage, (C) 2016 Minio, Inc. + * Minio Cloud Storage, (C) 2016, 2017 Minio, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package cmd +package words import ( "math"