Skip to content

Commit

Permalink
Merge pull request #3 from mergemaven11/add-command
Browse files Browse the repository at this point in the history
with add cmd & pytest wf
  • Loading branch information
mergemaven11 authored May 23, 2024
2 parents 6939a08 + ece47fb commit 85831eb
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 13 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Run Pytest

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
test:
name: Run Pytest
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.x # Specify the Python version you want to use

- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python -
export PATH="$HOME/.poetry/bin:$PATH"
- name: Install dependencies
run: |
poetry install
- name: Run pytest
run: |
poetry run pytest
15 changes: 12 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -13,12 +13,12 @@ repos:
- id: isort

- repo: https://github.com/psf/black
rev: 23.3.0
rev: 24.4.2
hooks:
- id: black

- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v1.5.7
rev: v2.0.4
hooks:
- id: autopep8

Expand All @@ -27,6 +27,15 @@ repos:
hooks:
- id: mypy

- repo: local
hooks:
- id: pytest-check
name: pytest-check
entry: pytest
language: system
pass_filenames: false
always_run: true

- repo: local
hooks:
- id: pylint
Expand Down
10 changes: 9 additions & 1 deletion cli/handlers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Module containing handlers for the CLI commands.
"""

import json
import typing as t
import uuid
Expand All @@ -14,7 +15,9 @@
console = Console()


def add_entry_to_file(entry_obj: t.Dict[str, t.Any], entries_file: str) -> None:
def add_entry_to_file(
entry_obj: t.Dict[str, t.Any], entries_file: str = utils.ENTRIES_FILE
) -> None:
"""
Add a JSON object representing a journal entry to the entries file.
Expand All @@ -39,6 +42,11 @@ def add_entry_to_file(entry_obj: t.Dict[str, t.Any], entries_file: str) -> None:
# Write the updated entry data back to the file
with open(entries_file, "w", encoding="utf-8") as f:
json.dump(entries_data, f, indent=4) # indent for pretty printing
console.print(
f"[bold green]Successfully added the following entry:[/bold green]\n"
f"{json.dumps(entry_obj, indent=4)}",
style="green",
)


# Searching an entry
Expand Down
20 changes: 11 additions & 9 deletions journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,28 @@


# Add imported commands to the main Typer application instance
@app.command()
def add(entries_file: str): # Add entries_file as an argument
@app.command(name="add", short_help="Add a new entry to your journal.")
def add(): # Add title as an argument
"""
Adds a new journal entry.
Prompts the user to enter a title and a journal entry.
Sends the data to the add handler to be added to the file.
Parameters:
entries_file (str): Path to the entries file.
Returns:
None
"""
title = typer.prompt("Please enter a title")
entry = typer.prompt("Please enter your journal entry")
# Send data to add handler
handler.add_entry_to_file(
entries_file=entries_file, entry_obj={"Title": title, "Entry": entry}
) # Pass entries_file argument
confirm = typer.confirm("Do you want to add this entry?")

if confirm:
# Send data to add handler
handler.add_entry_to_file(
entry_obj={"Title": title, "Entry": entry}
) # Pass entries_file argument
else:
typer.echo("Entry Discarded!")


# @app.command()
Expand Down
1 change: 1 addition & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module for testing all utils"""

import json
import os

Expand Down

0 comments on commit 85831eb

Please sign in to comment.