aboutsummaryrefslogtreecommitdiff
path: root/awwan.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-09-27 00:32:27 +0700
committerShulhan <ms@kilabit.info>2023-09-27 00:54:10 +0700
commitec249eb3ca99070b31e7a535219de9f2474df5e4 (patch)
tree118e6e6e1beb8a36a470331b2a379da3033096af /awwan.go
parentc595d849701d35e81c02e4a834abb4cd2d0a5933 (diff)
downloadawwan-ec249eb3ca99070b31e7a535219de9f2474df5e4.tar.xz
all: print any path relative to base directory
This is to minimize log length in stdout and stderr, which make it more readable.
Diffstat (limited to 'awwan.go')
-rw-r--r--awwan.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/awwan.go b/awwan.go
index e506ca5..02b855d 100644
--- a/awwan.go
+++ b/awwan.go
@@ -431,3 +431,15 @@ func lookupBaseDir(baseDir string) (dir string, err error) {
}
return dir, nil
}
+
+// relativePath return the relative path based on baseDir.
+// It will return path without baseDir prefix on success, or unchanged path
+// if no baseDir.
+func relativePath(baseDir, path string) (relpath string) {
+ var err error
+ relpath, err = filepath.Rel(baseDir, path)
+ if err != nil {
+ relpath = path
+ }
+ return relpath
+}