cheat-cli 0.1.1__tar.gz → 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cheat-cli
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: A terminal-first personal cheat sheet for Linux developers
5
5
  Author: Rejish
6
6
  License: MIT
@@ -1,33 +1,69 @@
1
1
  #!/usr/bin/env python3
2
2
 
3
3
  import sys
4
+ import shutil
5
+ from pathlib import Path
6
+
4
7
  import pandas as pd
5
8
  from tabulate import tabulate
6
9
  from importlib.resources import files
7
10
 
8
- # ---------- Helpers ----------
11
+ # ===============================
12
+ # Paths & Data Handling
13
+ # ===============================
14
+
15
+ def user_data_path() -> Path:
16
+ """
17
+ Location for user-modifiable data.
18
+ """
19
+ return Path.home() / ".local" / "share" / "cheat-cli" / "commands.csv"
9
20
 
10
- def get_csv_path():
11
- return files("cheat_cli").joinpath("data/commands.csv")
12
21
 
13
- def csv_path():
22
+ def packaged_csv_path():
23
+ """
24
+ Read-only CSV shipped inside the package.
25
+ """
14
26
  return files("cheat_cli").joinpath("data/commands.csv")
15
27
 
16
- def load_df():
17
- return pd.read_csv(csv_path())
18
28
 
19
- def save_df(df):
20
- df.to_csv(csv_path(), index=False)
29
+ def ensure_user_csv_exists() -> Path:
30
+ """
31
+ Ensure user CSV exists by copying from packaged CSV on first run.
32
+ """
33
+ path = user_data_path()
34
+ path.parent.mkdir(parents=True, exist_ok=True)
35
+
36
+ if not path.exists():
37
+ shutil.copy(packaged_csv_path(), path)
38
+
39
+ return path
40
+
21
41
 
22
- def print_table(df):
42
+ def load_df() -> pd.DataFrame:
43
+ return pd.read_csv(ensure_user_csv_exists())
44
+
45
+
46
+ def save_df(df: pd.DataFrame):
47
+ df.to_csv(user_data_path(), index=False)
48
+
49
+
50
+ # ===============================
51
+ # Output Helpers
52
+ # ===============================
53
+
54
+ def print_table(df: pd.DataFrame):
23
55
  if df.empty:
24
56
  print("\033[91mNo results found.\033[0m")
25
57
  return
58
+
26
59
  print(tabulate(df, headers="keys", tablefmt="fancy_grid", showindex=False))
27
60
 
28
- # ---------- Core Features ----------
29
61
 
30
- def search(df, term):
62
+ # ===============================
63
+ # Core Features
64
+ # ===============================
65
+
66
+ def search(df: pd.DataFrame, term: str):
31
67
  term = term.lower()
32
68
  mask = (
33
69
  df["tool"].str.lower().str.contains(term) |
@@ -37,8 +73,10 @@ def search(df, term):
37
73
  )
38
74
  print_table(df[mask])
39
75
 
40
- def add_interactive(df):
76
+
77
+ def add_interactive(df: pd.DataFrame):
41
78
  print("\033[94mInteractive add mode\033[0m")
79
+
42
80
  tool = input("Tool: ").strip()
43
81
  command = input("Command: ").strip()
44
82
  description = input("Description: ").strip()
@@ -52,14 +90,17 @@ def add_interactive(df):
52
90
  save_df(df)
53
91
  print("\033[92m✅ Command added.\033[0m")
54
92
 
55
- def delete_command(df, query):
93
+
94
+ def delete_command(df: pd.DataFrame, query: str):
56
95
  matches = df[df["command"].str.contains(query, case=False)]
96
+
57
97
  if matches.empty:
58
98
  print("\033[91mNo match found.\033[0m")
59
99
  return
60
100
 
61
101
  print_table(matches)
62
102
  confirm = input("Delete these entries? (yes/no): ").lower()
103
+
63
104
  if confirm != "yes":
64
105
  print("Cancelled.")
65
106
  return
@@ -68,23 +109,35 @@ def delete_command(df, query):
68
109
  save_df(df)
69
110
  print("\033[92m✅ Deleted.\033[0m")
70
111
 
71
- # ---------- Entry Point ----------
112
+
113
+ # ===============================
114
+ # Entry Point
115
+ # ===============================
72
116
 
73
117
  def main():
74
118
  df = load_df()
75
119
 
76
120
  if len(sys.argv) < 2:
77
- print("Usage: cheat <search> | cheat add | cheat delete <query>")
121
+ print("Usage:")
122
+ print(" cheat <search-term>")
123
+ print(" cheat add")
124
+ print(" cheat delete <query>")
78
125
  return
79
126
 
80
127
  cmd = sys.argv[1]
81
128
 
82
129
  if cmd == "add":
83
130
  add_interactive(df)
131
+
84
132
  elif cmd == "delete":
85
133
  if len(sys.argv) < 3:
86
134
  print("Usage: cheat delete <query>")
87
135
  return
88
136
  delete_command(df, sys.argv[2])
137
+
89
138
  else:
90
- search(df, cmd)
139
+ search(df, cmd)
140
+
141
+
142
+ if __name__ == "__main__":
143
+ main()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cheat-cli
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: A terminal-first personal cheat sheet for Linux developers
5
5
  Author: Rejish
6
6
  License: MIT
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
5
5
 
6
6
  [project]
7
7
  name = "cheat-cli"
8
- version = "0.1.1"
8
+ version = "0.1.2"
9
9
  description = "A terminal-first personal cheat sheet for Linux developers"
10
10
  readme = "README.md"
11
11
  license = {text = "MIT"}
File without changes
File without changes
File without changes
File without changes