cheat-cli 0.1.0__py3-none-any.whl → 0.1.2__py3-none-any.whl

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.
cheat_cli/cli.py CHANGED
@@ -1,30 +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"
20
+
9
21
 
10
- def csv_path():
22
+ def packaged_csv_path():
23
+ """
24
+ Read-only CSV shipped inside the package.
25
+ """
11
26
  return files("cheat_cli").joinpath("data/commands.csv")
12
27
 
13
- def load_df():
14
- return pd.read_csv(csv_path())
15
28
 
16
- def save_df(df):
17
- 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
+
18
41
 
19
- 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):
20
55
  if df.empty:
21
56
  print("\033[91mNo results found.\033[0m")
22
57
  return
58
+
23
59
  print(tabulate(df, headers="keys", tablefmt="fancy_grid", showindex=False))
24
60
 
25
- # ---------- Core Features ----------
26
61
 
27
- def search(df, term):
62
+ # ===============================
63
+ # Core Features
64
+ # ===============================
65
+
66
+ def search(df: pd.DataFrame, term: str):
28
67
  term = term.lower()
29
68
  mask = (
30
69
  df["tool"].str.lower().str.contains(term) |
@@ -34,8 +73,10 @@ def search(df, term):
34
73
  )
35
74
  print_table(df[mask])
36
75
 
37
- def add_interactive(df):
76
+
77
+ def add_interactive(df: pd.DataFrame):
38
78
  print("\033[94mInteractive add mode\033[0m")
79
+
39
80
  tool = input("Tool: ").strip()
40
81
  command = input("Command: ").strip()
41
82
  description = input("Description: ").strip()
@@ -49,14 +90,17 @@ def add_interactive(df):
49
90
  save_df(df)
50
91
  print("\033[92m✅ Command added.\033[0m")
51
92
 
52
- def delete_command(df, query):
93
+
94
+ def delete_command(df: pd.DataFrame, query: str):
53
95
  matches = df[df["command"].str.contains(query, case=False)]
96
+
54
97
  if matches.empty:
55
98
  print("\033[91mNo match found.\033[0m")
56
99
  return
57
100
 
58
101
  print_table(matches)
59
102
  confirm = input("Delete these entries? (yes/no): ").lower()
103
+
60
104
  if confirm != "yes":
61
105
  print("Cancelled.")
62
106
  return
@@ -65,23 +109,35 @@ def delete_command(df, query):
65
109
  save_df(df)
66
110
  print("\033[92m✅ Deleted.\033[0m")
67
111
 
68
- # ---------- Entry Point ----------
112
+
113
+ # ===============================
114
+ # Entry Point
115
+ # ===============================
69
116
 
70
117
  def main():
71
118
  df = load_df()
72
119
 
73
120
  if len(sys.argv) < 2:
74
- 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>")
75
125
  return
76
126
 
77
127
  cmd = sys.argv[1]
78
128
 
79
129
  if cmd == "add":
80
130
  add_interactive(df)
131
+
81
132
  elif cmd == "delete":
82
133
  if len(sys.argv) < 3:
83
134
  print("Usage: cheat delete <query>")
84
135
  return
85
136
  delete_command(df, sys.argv[2])
137
+
86
138
  else:
87
139
  search(df, cmd)
140
+
141
+
142
+ if __name__ == "__main__":
143
+ main()
@@ -0,0 +1,2 @@
1
+ tool,command,description,tags
2
+ git,git status,Show current git working tree status,repo state branch
@@ -1,11 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cheat-cli
3
- Version: 0.1.0
4
- Summary: A terminal-first cheat sheet CLI for Linux developers
5
- Author-email: RejishJ <rejish.j.d@gmail.com>
3
+ Version: 0.1.2
4
+ Summary: A terminal-first personal cheat sheet for Linux developers
5
+ Author: Rejish
6
6
  License: MIT
7
- Project-URL: Homepage, https://github.com/RejishJ/cheat-cli
8
- Project-URL: Repository, https://github.com/RejishJ/cheat-cli
9
7
  Requires-Python: >=3.8
10
8
  Description-Content-Type: text/markdown
11
9
  License-File: LICENSE
@@ -0,0 +1,9 @@
1
+ cheat_cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ cheat_cli/cli.py,sha256=9cccsEHK4fr7p903frFJsAZIgtSSWozL0zM7QPFOXXc,3279
3
+ cheat_cli/data/commands.csv,sha256=jVdIJT15eCbhiVoneVLQOViYYN2o3P6S2p7_xQEow3c,100
4
+ cheat_cli-0.1.2.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ cheat_cli-0.1.2.dist-info/METADATA,sha256=MZvPYJcH53ST1fh6UqRhThStTyGC-LMOzDdGUnXYjcM,648
6
+ cheat_cli-0.1.2.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
7
+ cheat_cli-0.1.2.dist-info/entry_points.txt,sha256=SHbwyH9qo8Z3HQUGAGkJ624xXYLf1rTk61rG-5gmqhM,45
8
+ cheat_cli-0.1.2.dist-info/top_level.txt,sha256=75FJyvpbIOdhtg301BIkrXWfR3j9DCZ2G0ZpcSi7tfc,10
9
+ cheat_cli-0.1.2.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- cheat_cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- cheat_cli/cli.py,sha256=GiXsvqYCxkZDOX61uMrdOgM3vHo-j_90F6wr6QdUeNI,2245
3
- cheat_cli-0.1.0.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- cheat_cli-0.1.0.dist-info/METADATA,sha256=F0U5BitG02lNOyRNU7pWoFqUE4EsJIMwdTIEB0-MFP4,795
5
- cheat_cli-0.1.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
6
- cheat_cli-0.1.0.dist-info/entry_points.txt,sha256=SHbwyH9qo8Z3HQUGAGkJ624xXYLf1rTk61rG-5gmqhM,45
7
- cheat_cli-0.1.0.dist-info/top_level.txt,sha256=75FJyvpbIOdhtg301BIkrXWfR3j9DCZ2G0ZpcSi7tfc,10
8
- cheat_cli-0.1.0.dist-info/RECORD,,