diff --git a/CHANGES.md b/CHANGES.md index 2739095..8c02472 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ # Changes +## 2.0.1 + +Streamlined feedback after clones, pulls and removed. + ## 2.0.0 Entire codebase rewritten to be more managable and cleaner. diff --git a/Makefile b/Makefile deleted file mode 100644 index 8004f1f..0000000 --- a/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# Makefile for gitman: -BIN_DIR="/usr/local/bin/" -BUILD_FLAGS="-d:release" - -gitman: src/gitman.nim - nimble build $(BUILD_FLAGS) - -build: gitman - -install: gitman - sudo mv gitman $(BIN_DIR) - diff --git a/gitman.nimble b/gitman.nimble index 040ab3d..69f9bf0 100644 --- a/gitman.nimble +++ b/gitman.nimble @@ -1,6 +1,6 @@ # Package -version = "2.0.0" +version = "2.0.1" author = "nirokay" description = "A git-repo manager that lets you easily update multiple git repositories in a specified directory." license = "GPL-3.0-only" diff --git a/src/error.nim b/src/error.nim index 7d545c0..0266df0 100644 --- a/src/error.nim +++ b/src/error.nim @@ -1,18 +1,22 @@ -import strformat, terminal +import std/[strutils, strformat, terminal] const help_io_text: string = "\nPlease check if you have needed permissions." see_help_text: string = "\nSee `help` for a list of valid args." -type ErrorType* = enum - IO_FAILURE = "Failed to read/write from/to disk." & help_io_text, - READ_ERROR = "Failed to read from disk." & help_io_text, - WRITE_ERROR = "Failed to write to disk." & help_io_text, +type + ErrorType* = enum + IO_FAILURE = "Failed to read/write from/to disk." & help_io_text, + READ_ERROR = "Failed to read from disk." & help_io_text, + WRITE_ERROR = "Failed to write to disk." & help_io_text, - OPERATION_NONE = "No arguments provided." & see_help_text, - OPERATION_UNKNOWN = "Invalid argument." & see_help_text, + OPERATION_NONE = "No arguments provided." & see_help_text, + OPERATION_UNKNOWN = "Invalid argument." & see_help_text, - INVALID_ARGUMENTS_AMOUNT = "Invalid amounts of arguments." + INVALID_ARGUMENTS_AMOUNT = "Invalid amounts of arguments." + ErrorStatus* = object + successes*: int + failures*: seq[string] proc handle*(error: ErrorType, msg: string = "(none provided)") = @@ -22,3 +26,20 @@ proc handle*(error: ErrorType, msg: string = "(none provided)") = &"Details: {msg}" quit(1) + +proc print(error: ErrorStatus, success_message, error_message: string) = + styledEcho fgGreen, &"Successful {success_message}: {error.successes}", fgDefault + if error.failures.len() != 0: + styledEcho fgRed, &"Failed {error_message}:", fgDefault + echo "\t" & error.failures.join("\n\t") + +proc print_after_clone*(error: ErrorStatus) = + error.print("clones", &"to clone from following {error.failures.len()} repositories") + +proc print_after_pull*(error: ErrorStatus) = + error.print("pulls", &"to pull changes from following {error.failures.len()} repositories") + +proc print_after_remove*(error: ErrorStatus) = + error.print("removes", &"to remove following {error.failures.len()} repositories") + + diff --git a/src/fileio.nim b/src/fileio.nim index dbad721..f12a340 100644 --- a/src/fileio.nim +++ b/src/fileio.nim @@ -1,4 +1,4 @@ -import os, strformat +import std/[os, strformat] import error # ----------------------------------------------------------------------------- @@ -40,7 +40,7 @@ proc get_valid_git_dirs_names*(): seq[string] = result.add(dir.splitPath().tail) return result -proc remove_git_dirs*(dirs: seq[string]): tuple[successes: int, failures: seq[string]] = +proc remove_git_dirs*(dirs: seq[string]): ErrorStatus = ## Removes all directories and returns amount of successes and a sequence of failed directories for dir in dirs: try: diff --git a/src/globals.nim b/src/globals.nim index fe7ea70..ff354db 100644 --- a/src/globals.nim +++ b/src/globals.nim @@ -2,7 +2,7 @@ import std/os const PROJECT_NAME*: string = "gitman" - PROJECT_VERSION*: string = "2.0.0" + PROJECT_VERSION*: string = "2.0.1" PROJECT_WEBSITE*: string = "https://github.com/nirokay/gitman/" PROJECT_DESCRIPTION*: string = "A git-repo manager that lets you easily update multiple git repositories in a specified directory." PROJECT_AUTHORS*: seq[string] = @["nirokay"] diff --git a/src/operations/defs.nim b/src/operations/defs.nim index 30fc702..d510943 100644 --- a/src/operations/defs.nim +++ b/src/operations/defs.nim @@ -1,12 +1,9 @@ -import options +import std/options import types, procs proc add(op: Operation) = operations.add(op) -proc todo(_: seq[string]) = - echo "Function not yet implemented..." - # ----------------------------------------------------------------------------- diff --git a/src/operations/gitcommands.nim b/src/operations/gitcommands.nim index 3f845f2..b786795 100644 --- a/src/operations/gitcommands.nim +++ b/src/operations/gitcommands.nim @@ -1,4 +1,4 @@ -import os, strutils, strformat +import std/[os, strutils, strformat] const git_executable: string = when defined(windows): "git.exe" diff --git a/src/operations/procs.nim b/src/operations/procs.nim index 091b39a..76e347e 100644 --- a/src/operations/procs.nim +++ b/src/operations/procs.nim @@ -1,5 +1,5 @@ import std/[os, strutils, strformat, options, terminal] -import ../globals, ../fileio, types, gitcommands +import ../globals, ../fileio, ../error, types, gitcommands using op_args: seq[string] @@ -32,23 +32,17 @@ proc listCommand*(_) = proc cloneCommand*(op_args) = - var - successes: seq[string] - failures: seq[string] + var status: ErrorStatus git_repo_path.setCurrentDir() for repo in op_args: let succ: int = GIT_CLONE.execute(repo) # Save successes and failures: - if succ == 0: successes.add(repo) - else: failures.add(repo) + if succ == 0: status.successes += 1 + else: status.failures.add(repo) stdout.write "\n" - if successes.len() != 0: - echo &"Successful clones: {successes.len()}" - if failures.len() != 0: - echo &"Failed clones: {failures.len()}" - echo "\t" & failures.join("\n\t") + status.print_after_clone() proc removeCommand*(op_args) = @@ -72,12 +66,9 @@ proc removeCommand*(op_args) = quit(1) # Remove dirs: - let status: tuple[successes: int, failures: seq[string]] = remove_git_dirs(dirs_to_delete) - - echo &"Successfully removed {status.successes} repositories!" - if status.failures.len() > 0: - echo &"Failed on {status.failures.len()} repositories:" - echo "\t" & status.failures.join("\n\t") + let status: ErrorStatus = remove_git_dirs(dirs_to_delete) + stdout.write("\n") + status.print_after_remove() proc pullCommand*(op_args) = @@ -99,7 +90,7 @@ proc pullCommand*(op_args) = quit(1) # cd into directories and pull changes: - var status: tuple[successes: int, failures: seq[string]] + var status: ErrorStatus for dir in dirs: try: styledEcho fgYellow, &"Pulling {dir}...", fgDefault @@ -109,10 +100,7 @@ proc pullCommand*(op_args) = except OSError: status.failures.add(dir) - # Echo result: - styledEcho fgGreen, &"\nSuccessful pulls: {status.successes}", fgDefault - if status.failures.len() > 0: - styledEcho fgRed, &"Failed to pull changes from following {status.failures.len()} repositories:\n" , fgDefault, - "\t" & status.failures.join("\n\t") + stdout.write("\n") + status.print_after_pull()