-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #180 from srm09/bug/fix-relative-paths
Allows relative paths for kubeconfig and argsfile
- Loading branch information
Showing
5 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) 2020 VMware, Inc. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package util | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
// ExpandPath converts the file path to include the home directory when prefixed with `~`. | ||
func ExpandPath(path string) (string, error) { | ||
home, err := os.UserHomeDir() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
if path[0] == '~' { | ||
path = filepath.Join(home, path[1:]) | ||
} | ||
return path, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) 2020 VMware, Inc. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package util | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("ExpandPath", func() { | ||
|
||
It("returns the same path when input does not contain ~", func() { | ||
input := "/foo/bar" | ||
path, err := ExpandPath(input) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(path).To(Equal(input)) | ||
}) | ||
|
||
It("replaces the ~ with home directory path", func() { | ||
input := "~/foo/bar" | ||
path, err := ExpandPath(input) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(path).NotTo(Equal(input)) | ||
Expect(path).NotTo(ContainSubstring("~")) | ||
}) | ||
}) |