Skip to content

Commit

Permalink
feat: support bulk operation for --delete
Browse files Browse the repository at this point in the history
  • Loading branch information
Justaus3r authored Aug 9, 2022
1 parent 541ebff commit c8ccdc3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
8 changes: 4 additions & 4 deletions ceg/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"""

from .ceg import Ceg
from typing import List , Dict, Optional
from typing import List, Dict, Optional


class CegApi:
Expand Down Expand Up @@ -164,17 +164,17 @@ def patch(
self.ceg_instance.patch()
return self.ceg_instance.response_status_str

def delete(self, gist_id: str) -> str:
def delete(self, *args) -> str:
"""Delete an existing gist.
Args:
gist_id = gist_id for the gist,that is to be deleted.
gist_id = arbitrary amount of gist-ids.
Returns:
Returns HTTP call response status in string format.
"""
self.ceg_instance.http_operation = "delete"
self.ceg_instance.arg_val = gist_id
self.ceg_instance.arg_val = args
self.ceg_instance.delete()
return self.ceg_instance.response_status_str

Expand Down
9 changes: 7 additions & 2 deletions ceg/arg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def reccord_arguments(self) -> argparse.Namespace:
Returns the argparse.Namespace object containing all the arguments.
"""
# TODO: for [v0.2.0]: switch for returning enhanced return codes for better script compatibility.
# TODO: for [v0.2.0 | v0.3.0]: switch for returning enhanced return codes for better script compatibility.
# TODO: for [v0.2.0 | v0.3.0]: Use pickle to use serialized cache from local storage(Security implications?).
# TODO: for [v0.2.0 | v0.3.0]: Change arg parser to flask/click or python-poetry/cleo
group = self.add_mutually_exclusive_group()
Expand Down Expand Up @@ -94,7 +94,12 @@ def reccord_arguments(self) -> argparse.Namespace:
nargs="+",
)
group.add_argument(
"-d", "--delete", help="remove a gist", metavar="GISTID", type=str
"-d",
"--delete",
help="remove gist(s)",
metavar="GISTID",
type=str,
nargs="+",
)
group.add_argument(
"-l",
Expand Down
13 changes: 8 additions & 5 deletions ceg/ceg.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,10 +475,12 @@ def patch(self) -> None:

def delete(self) -> None:
"""Delete an existing gist."""
self.logger.info("Searching and deleting gist...")
self.end_point += "/" + self.arg_val # type: ignore
self.__send_http_request()
self.logger.info("Gist deleted sucessfully!.")
endpoint_copy: str = self.end_point
for gist in self.arg_val: # type: ignore
self.logger.info(f"Searching and deleting gist with id '{gist[:4]}...'")
self.end_point = "{}/{}".format(endpoint_copy, gist) # type: ignore
self.__send_http_request()
self.logger.info("Gist deleted sucessfully!.")

def backup(self) -> None:
"""Create a local backup of all the gists."""
Expand Down Expand Up @@ -506,7 +508,8 @@ def list_other(self) -> Optional[List[Dict[str, str]]]:
(Optionally) returns a list containing all gists.
"""
user_gist_info: Optional[List[Dict[str, str]]] = self.list(
end_point=f"https://api.github.com/users/{self.arg_val}/gists", no_header=True
end_point=f"https://api.github.com/users/{self.arg_val}/gists",
no_header=True,
)
if not self.to_stdout:
return user_gist_info
Expand Down
4 changes: 3 additions & 1 deletion ceg/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ class UtilInfo:
For more usage help, check out https://www.github.com/justaus3r/ceg/#examples"""
DESCRIPTION: str = "A simple gist crud utility."
VERSION: str = "0.1.1"
# Caution(message to myself): Be careful when updating the version because
# wrong updates can be a mess.
VERSION: str = "0.2.0"


def exception_executioner(exception_obj) -> None:
Expand Down

0 comments on commit c8ccdc3

Please sign in to comment.