Skip to content

Commit b1bb149

Browse files
committed
introduced a function to mount a subpath
1 parent 5cd5481 commit b1bb149

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/main/scala/org/polystat/cli/InputUtils.scala renamed to src/main/scala/org/polystat/cli/util/InputUtils.scala

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,38 @@
1-
package org.polystat.cli
1+
package org.polystat.cli.util
2+
23
import cats.data.NonEmptyList
34
import cats.effect.IO
45
import fs2.Stream
56
import fs2.io.file.Files
67
import fs2.io.file.Path
78
import fs2.io.stdinUtf8
89
import fs2.text.utf8
10+
import org.polystat.cli.HoconConfig
11+
import org.polystat.cli.PolystatConfig.Input
12+
import org.polystat.cli.PolystatConfig.PolystatUsage
913

1014
import java.io.FileNotFoundException
11-
12-
import PolystatConfig.{Input, PolystatUsage}
13-
1415
object 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

Comments
 (0)