mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
--gc.
This commit is contained in:
parent
2c0f930764
commit
d0977b17e7
4 changed files with 116 additions and 1 deletions
|
@ -26,6 +26,9 @@ class Args {
|
|||
"actually running them")
|
||||
var dryRun: Boolean = false
|
||||
|
||||
@Parameter(names = arrayOf("--gc"), description = "Delete old files")
|
||||
var gc: Boolean = false
|
||||
|
||||
@Parameter(names = arrayOf("--help", "--usage"), description = "Display the help")
|
||||
var usage: Boolean = false
|
||||
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
package com.beust.kobalt.misc
|
||||
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
import java.nio.file.StandardCopyOption
|
||||
|
||||
class Io(val dryRun: Boolean = false) {
|
||||
fun mkdirs(dir: String) {
|
||||
log("mkdirs $dir")
|
||||
if (! dryRun) {
|
||||
File(dir).mkdirs()
|
||||
}
|
||||
}
|
||||
|
||||
fun rm(path: String) {
|
||||
log("rm $path")
|
||||
|
||||
if (! dryRun) {
|
||||
File(path).deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
fun moveFile(from: File, toDir: File) {
|
||||
log("mv $from $toDir")
|
||||
if (! dryRun) {
|
||||
require(from.exists(), { -> "$from should exist" })
|
||||
require(from.isFile, { -> "$from should be a file" })
|
||||
require(toDir.isDirectory, { -> "$toDir should be a file"})
|
||||
|
||||
val toFile = File(toDir, from.name)
|
||||
Files.move(Paths.get(from.absolutePath), Paths.get(toFile.absolutePath), StandardCopyOption.ATOMIC_MOVE)
|
||||
}
|
||||
}
|
||||
|
||||
fun copyDirectory(from: File, toDir: File) {
|
||||
log("cp -r $from $toDir")
|
||||
|
||||
if (! dryRun) {
|
||||
KFiles.copyRecursively(from, toDir)
|
||||
require(from.exists(), { -> "$from should exist" })
|
||||
require(from.isDirectory, { -> println("$from should be a directory")})
|
||||
require(toDir.isDirectory, { -> println("$toDir should be a file")})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fun rmDir(dir: File) {
|
||||
log("rm -rf $dir")
|
||||
|
||||
if (! dryRun) {
|
||||
require(dir.isDirectory, { -> println("$dir should be a directory")})
|
||||
dir.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
fun mkdir(dir: File) {
|
||||
log("rm -rf $dir")
|
||||
if (! dryRun) {
|
||||
dir.mkdirs()
|
||||
}
|
||||
}
|
||||
|
||||
private fun log(s: String) {
|
||||
log(1, "[Io] $s")
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue