Skip to content

Commit

Permalink
improved feedback after pull, clone, remove and made some code more c…
Browse files Browse the repository at this point in the history
…onsistent-looking
  • Loading branch information
nirokay committed May 12, 2023
1 parent 42887d2 commit db65f8c
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 52 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
12 changes: 0 additions & 12 deletions Makefile

This file was deleted.

2 changes: 1 addition & 1 deletion gitman.nimble
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
37 changes: 29 additions & 8 deletions src/error.nim
Original file line number Diff line number Diff line change
@@ -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)") =
Expand All @@ -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")


4 changes: 2 additions & 2 deletions src/fileio.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os, strformat
import std/[os, strformat]
import error

# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/globals.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
5 changes: 1 addition & 4 deletions src/operations/defs.nim
Original file line number Diff line number Diff line change
@@ -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..."



# -----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/operations/gitcommands.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os, strutils, strformat
import std/[os, strutils, strformat]

const git_executable: string =
when defined(windows): "git.exe"
Expand Down
34 changes: 11 additions & 23 deletions src/operations/procs.nim
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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) =
Expand All @@ -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) =
Expand All @@ -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
Expand All @@ -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()


0 comments on commit db65f8c

Please sign in to comment.