-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added option to set a file with the list of files to delete
FossilOrigin-Name: b502f443c84edac088a91855ef4464a1b491ea27d94eaf81249c989a5cfe6003
- Loading branch information
Showing
1 changed file
with
16 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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], | ||
|
@@ -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""") | ||
|
@@ -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 <[email protected]> | ||
License: 3-Clause BSD""") | ||
|
@@ -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 | ||
|
@@ -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: | ||
|
@@ -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() | ||
|
||
|