Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat : Added ls() method with numbered output for files in stash directory #104

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions package/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,31 @@
import shutil


def display(snippet_name):
def display(snippet_name=None):
try:
base_dir = os.path.dirname(__file__)
snippet_path = os.path.join(base_dir, "stash", f"{snippet_name}.py")
output_path = os.path.join(
base_dir, f"{snippet_name}.py"
)
shutil.copyfile(snippet_path, output_path)
if snippet_name:
base_dir = os.path.dirname(__file__)
snippet_path = os.path.join(base_dir, "stash", f"{snippet_name}.py")
output_path = os.path.join(
base_dir, f"{snippet_name}.py"
)
shutil.copyfile(snippet_path, output_path)
else:
ls() #Call ls() if snippet_name is not provided
except Exception as e:
print(f"Syntax Error: {e}")

def ls():
stash_dir = os.path.join(os.path.dirname(__file__), 'stash')

# Get the list of files in the stash directory
try:
files = os.listdir(stash_dir)
if not files:
print("No files found in stash directory.")
else:
# Format the output as numbered list
for i, file in enumerate(files, 1):
print(f"{i}. {file}")
except FileNotFoundError:
print("Stash directory not found.")