File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 99 "errors"
1010 "io/fs"
1111 "os"
12+ "os/user"
1213 "path/filepath"
14+ "strings"
1315
1416 "github.com/adrg/xdg"
1517 "github.com/getkin/kin-openapi/openapi3"
@@ -40,10 +42,28 @@ func Complete(opts ...Options) (result Options) {
4042 }
4143 if result .CacheDir == "" {
4244 result .CacheDir = filepath .Join (xdg .CacheHome , version .ProgramName )
45+ } else if ! filepath .IsAbs (result .CacheDir ) {
46+ var err error
47+ result .CacheDir , err = makeAbsolute (result .CacheDir )
48+ if err != nil {
49+ result .CacheDir = filepath .Join (xdg .CacheHome , version .ProgramName )
50+ }
4351 }
4452 return
4553}
4654
55+ func makeAbsolute (path string ) (string , error ) {
56+ if strings .HasPrefix (path , "~" + string (filepath .Separator )) {
57+ usr , err := user .Current ()
58+ if err != nil {
59+ return "" , err
60+ }
61+
62+ return filepath .Join (usr .HomeDir , path [2 :]), nil
63+ }
64+ return filepath .Abs (path )
65+ }
66+
4767type noCacheKey struct {}
4868
4969func IsNoCache (ctx context.Context ) bool {
You can’t perform that action at this time.
0 commit comments