1- package org .polystat .cli
1+ package org .polystat .cli .util
2+
23import cats .data .NonEmptyList
34import cats .effect .IO
45import fs2 .Stream
56import fs2 .io .file .Files
67import fs2 .io .file .Path
78import fs2 .io .stdinUtf8
89import fs2 .text .utf8
10+ import org .polystat .cli .HoconConfig
11+ import org .polystat .cli .PolystatConfig .Input
12+ import org .polystat .cli .PolystatConfig .PolystatUsage
913
1014import java .io .FileNotFoundException
11-
12- import PolystatConfig .{Input , PolystatUsage }
13-
1415object InputUtils :
16+
1517 extension (path : Path )
1618
19+ def mount (to : Path , relativelyTo : Path ): Path =
20+ val relativePath =
21+ relativelyTo.absolute.normalize.relativize(path.absolute.normalize)
22+ to.normalize / relativePath
23+
24+ def filenameNoExt : String =
25+ val fileName = path.fileName.toString
26+ fileName.splitAt(fileName.indexOf(" ." ))._1
27+
1728 def createDirIfDoesntExist : IO [Path ] =
1829 Files [IO ]
1930 .exists(path)
2031 .ifM(
2132 ifTrue = IO .pure(path),
2233 ifFalse = Files [IO ].createDirectories(path).as(path),
2334 )
35+
2436 def replaceExt (newExt : String ): Path =
2537 Path (
2638 path.toString
@@ -52,9 +64,6 @@ object InputUtils:
5264 )
5365 end extension
5466
55- def relativePath (to : Path , path : Path ): Path =
56- to.absolute.normalize.relativize(path.absolute.normalize)
57-
5867 def readCodeFromFile (ext : String , path : Path ): Stream [IO , (Path , String )] =
5968 Stream
6069 .emit(path)
@@ -74,7 +83,7 @@ object InputUtils:
7483 Files [IO ]
7584 .readAll(path)
7685 .through(utf8.decode)
77- .map(code => (relativePath(to = dir, path = path) , code))
86+ .map(code => (path, code))
7887 )
7988
8089 def readCodeFromStdin : Stream [IO , String ] = stdinUtf8[IO ](4096 ).bufferAll
0 commit comments