diff options
| author | 2023-04-28 01:36:44 +0800 | |
|---|---|---|
| committer | 2023-04-28 01:36:44 +0800 | |
| commit | dd84b9d64fb98746a230cd24233ff50a562c39c9 (patch) | |
| tree | b583261ef00b3afe72ec4d6dacb31e57779a6faf /cli/internal/turbopath/relative_unix_path.go | |
| parent | 0b46fcd72ac34382387b2bcf9095233efbcc52f4 (diff) | |
| download | HydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.tar.gz HydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.zip | |
Diffstat (limited to 'cli/internal/turbopath/relative_unix_path.go')
| -rw-r--r-- | cli/internal/turbopath/relative_unix_path.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/cli/internal/turbopath/relative_unix_path.go b/cli/internal/turbopath/relative_unix_path.go new file mode 100644 index 0000000..05829e2 --- /dev/null +++ b/cli/internal/turbopath/relative_unix_path.go @@ -0,0 +1,31 @@ +package turbopath + +import ( + "path" + "path/filepath" +) + +// RelativeUnixPath is a relative path using Unix `/` separators. +type RelativeUnixPath string + +// ToString returns a string represenation of this Path. +// Used for interfacing with APIs that require a string. +func (p RelativeUnixPath) ToString() string { + return string(p) +} + +// ToSystemPath converts a RelativeUnixPath to a RelativeSystemPath. +func (p RelativeUnixPath) ToSystemPath() RelativeSystemPath { + return RelativeSystemPath(filepath.FromSlash(p.ToString())) +} + +// ToUnixPath converts a RelativeUnixPath to a RelativeSystemPath. +func (p RelativeUnixPath) ToUnixPath() RelativeUnixPath { + return p +} + +// Join appends relative path segments to this RelativeUnixPath. +func (p RelativeUnixPath) Join(additional ...RelativeUnixPath) RelativeUnixPath { + cast := RelativeUnixPathArray(additional) + return RelativeUnixPath(path.Join(p.ToString(), path.Join(cast.ToStringArray()...))) +} |
