Skip to content

Commit

Permalink
fix: error checking in CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Destructive committed Jul 17, 2022
1 parent e0202ed commit 0b1a308
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
28 changes: 18 additions & 10 deletions crossposter/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,26 @@ def get_default_or_input(dictionary, keys):


def main():
file_markdown = sys.argv[1]
while not Path(file_markdown).exists():
parser = argparse.ArgumentParser()
if len(sys.argv)<2:
file_markdown = input("Enter the filename: ")
else:
file_markdown = sys.argv[1]
while not file_markdown:
print(f"No File Found with name {file_markdown}!")
file_markdown = input("Enter the filename: ")
if Path(file_markdown).exists():
break
if file_markdown:
if Path(file_markdown).exists():
break
else:
continue

parser = argparse.ArgumentParser()
parser.add_argument('Path', metavar='path', type=str, nargs='?', const=1, default=file_markdown, help='the path to file')
parser.add_argument("--dev", action="store_true", help='Post to dev.to')
parser.add_argument("--med", action="store_true", help='Post to medium.com')
parser.add_argument("--cdb", action="store_true", help='Post to codenewbie')
args = parser.parse_args()

post = frontmatter.load(file_markdown)

Expand Down Expand Up @@ -77,12 +91,6 @@ def main():
lines.append("codenewbie:\n")
f.writelines(lines)

parser = argparse.ArgumentParser()
parser.add_argument('Path', metavar='path',type=str,help='the path to file')
parser.add_argument("--dev", action="store_true", help='Post to dev.to')
parser.add_argument("--med", action="store_true", help='Post to medium.com')
parser.add_argument("--cdb", action="store_true", help='Post to codenewbie')
args = parser.parse_args()

if args.dev:
devto(article, output)
Expand Down
1 change: 1 addition & 0 deletions crossposter/publications/codenewbie.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

def codenewbie(article, output):

print("Cross-Posting on codenewbie.community")
codenewbie_keys = []
for line in open("keys.txt", "r"):
if line.startswith("codenewbie:"):
Expand Down
1 change: 1 addition & 0 deletions crossposter/publications/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

def devto(article, output):

print("Cross-Posting on dev.to")
dev_keys = []
for line in open("keys.txt", "r"):
if line.startswith("dev.to:"):
Expand Down
1 change: 1 addition & 0 deletions crossposter/publications/medium.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

def medium(article, output):

print("Cross-Posting on medium.com")
USERNAME_ENDPOINT = "https://api.medium.com/v1/me"

for line in open("keys.txt", "r"):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

HERE = pathlib.Path(__file__).parent

VERSION = "0.4.3"
VERSION = "0.4.5"
PACKAGE_NAME = "crossposter"
AUTHOR = "Meet Gor"
AUTHOR_EMAIL = "[email protected]"
Expand Down

0 comments on commit 0b1a308

Please sign in to comment.