Skip to content

Commit

Permalink
feat: added option to set a file with the list of files to delete
Browse files Browse the repository at this point in the history
FossilOrigin-Name: b502f443c84edac088a91855ef4464a1b491ea27d94eaf81249c989a5cfe6003
  • Loading branch information
thindil committed Dec 23, 2024
1 parent 2da7db5 commit 5521042
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/beastcleaner.nim
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

## The main module of the program.

import std/[os, osproc, parseopt]
import std/[os, osproc, parseopt, strutils, terminal]
import contracts

proc showCommandLineHelp() {.sideEffect, raises: [], tags: [WriteIOEffect],
Expand All @@ -37,8 +37,9 @@ proc showCommandLineHelp() {.sideEffect, raises: [], tags: [WriteIOEffect],
body:
try:
stdout.writeLine(x = """Available options are:
-h, --help - Show this help and quit
-v, --version - Show the program version info
-h, --help - Show this help and quit
-v, --version - Show the program version info
-f, --fileslist - The file to which the list of not managed files will be written
Available arguments are:
clean - Clean interactively the system""")
Expand All @@ -58,7 +59,7 @@ proc showProgramVersion() {.sideEffect, raises: [], tags: [WriteIOEffect],
body:
try:
stdout.writeLine(x = """
Beastcleaner version: 0.1.0
Beastcleaner version: 0.0.1
Copyright: 2024 Bartek Jasicki <thindil@laeran.pl.eu.org>
License: 3-Clause BSD""")
Expand All @@ -83,7 +84,7 @@ proc main() {.raises: [], tags: [ReadIOEffect, WriteIOEffect, ExecIOEffect,
awkScript: Setting = "/tmp/beastcleaner.awk"
pkgList: Setting = "/tmp/list1.txt"
filesList: Setting = "/tmp/list2.txt"
filesDiff: Setting = "/tmp/beastdiff.txt"
var filesDiff: Setting = "/tmp/beastdiff.txt"
var action: Actions = show

# Check the program's arguments and options
Expand All @@ -98,6 +99,8 @@ proc main() {.raises: [], tags: [ReadIOEffect, WriteIOEffect, ExecIOEffect,
showCommandLineHelp()
of "v", "version":
showProgramVersion()
of "f", "fileslist":
filesDiff = options.val
else:
quit "Unknown option '" & options.key & "'. To see all available options, run the program with --help."
of cmdArgument:
Expand Down Expand Up @@ -156,8 +159,15 @@ proc main() {.raises: [], tags: [ReadIOEffect, WriteIOEffect, ExecIOEffect,
getCurrentExceptionMsg()
else:
try:
var answer: char = 'n'
for line in filesDiff.lines:
removeFile(file = line)
if answer != 'a':
write(f = stdout, s = "Delete file '" & line & "'? ([Y]es/[N]o/[A]ll/[C]ancel)")
answer = getch().toLowerAscii
if answer == 'c':
break
if answer in ['y', 'a']:
removeFile(file = line)
except IOError, OSError:
echo "Can't remove files. Reason: " & getCurrentExceptionMsg()

Expand Down

0 comments on commit 5521042

Please sign in to comment.