mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-10-01 01:36:09 -04:00
39 lines
1.0 KiB
Go
39 lines
1.0 KiB
Go
|
/*
|
||
|
Copyright (c) Edgeless Systems GmbH
|
||
|
|
||
|
SPDX-License-Identifier: AGPL-3.0-only
|
||
|
*/
|
||
|
|
||
|
/*
|
||
|
Package pathprefix is used to print correct filepaths for a configured workspace.
|
||
|
|
||
|
The default workspace is the current working directory.
|
||
|
Users may override the default workspace using the --workspace flag.
|
||
|
|
||
|
The functions defined here should be used when printing any filepath to the user,
|
||
|
as they might otherwise be incorrect if the user has changed the workspace.
|
||
|
|
||
|
The prefixer MUST not be used when accessing files, as the workspace is changed
|
||
|
using os.Chdir() before the command is executed.
|
||
|
*/
|
||
|
package pathprefix
|
||
|
|
||
|
import (
|
||
|
"path/filepath"
|
||
|
)
|
||
|
|
||
|
// PathPrefixer is used to prefix paths with the configured workspace.
|
||
|
type PathPrefixer struct {
|
||
|
workspace string
|
||
|
}
|
||
|
|
||
|
// New returns a new PathPrefixer.
|
||
|
func New(workspace string) PathPrefixer {
|
||
|
return PathPrefixer{workspace: workspace}
|
||
|
}
|
||
|
|
||
|
// PrefixPath prefixes the given path with the configured workspace.
|
||
|
func (p PathPrefixer) PrefixPath(path string) string {
|
||
|
return filepath.Clean(filepath.Join(p.workspace, path))
|
||
|
}
|