-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli_helpers.go
More file actions
39 lines (34 loc) · 827 Bytes
/
cli_helpers.go
File metadata and controls
39 lines (34 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"fmt"
"log/slog"
"os"
"path/filepath"
"github.com/themakers/cage/libcage"
)
func resolveRoot(wd string) (string, error) {
if wd != "" {
abs, err := filepath.Abs(wd)
if err != nil {
return "", err
}
st, err := os.Stat(filepath.Join(abs, ".cage"))
if err != nil {
if os.IsNotExist(err) {
return "", fmt.Errorf("-wd %s: no .cage directory", abs)
}
return "", err
}
if !st.IsDir() {
return "", fmt.Errorf("-wd %s: .cage is not a directory", abs)
}
return abs, nil
}
return libcage.FindRoot(".")
}
func newCage(logger *slog.Logger, root string) (*libcage.Cage, error) {
return libcage.New(libcage.NewOptions{Root: root, Logger: logger})
}
func newRawCage(logger *slog.Logger) (*libcage.Cage, error) {
return libcage.New(libcage.NewOptions{Logger: logger})
}