mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-02 06:16:08 -04:00
Move workspace path functions to sub-package of cmd
Signed-off-by: Daniel Weiße <dw@edgeless.systems>
This commit is contained in:
parent
99c579b45a
commit
89b342900f
21 changed files with 213 additions and 189 deletions
38
cli/internal/cmd/pathprefix/pathprefix.go
Normal file
38
cli/internal/cmd/pathprefix/pathprefix.go
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
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))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue