watcmd 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.
- watcmd-0.1.2/.gitignore +2 -0
- watcmd-0.1.2/LICENSE.txt +21 -0
- watcmd-0.1.2/PKG-INFO +91 -0
- watcmd-0.1.2/README.md +76 -0
- watcmd-0.1.2/pyproject.toml +31 -0
- watcmd-0.1.2/src/watcmd/__init__.py +70 -0
watcmd-0.1.2/.gitignore
ADDED
watcmd-0.1.2/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Alex Ramalho
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
watcmd-0.1.2/PKG-INFO
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: watcmd
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: c
|
|
5
|
+
Project-URL: Homepage, https://github.com/alramalho/wat-cli
|
|
6
|
+
Project-URL: Bug Tracker, https://github.com/alramalho/wat-cli/issues
|
|
7
|
+
Author-email: Alex Ramalho <alexandre.ramalho.1998@gmail.com>
|
|
8
|
+
License-File: LICENSE.txt
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Requires-Python: >=3.7
|
|
13
|
+
Requires-Dist: openai
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# watcmd
|
|
17
|
+
|
|
18
|
+
A CLI tool to get UNIX commands from text explanations using AI
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
You can install `watcmd` directly from PyPI:
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
pip install watcmd
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Setup
|
|
29
|
+
|
|
30
|
+
After installation, you need to configure your Anthropic API key. You can do this by running:
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
watcmd setup YOUR_API_KEY
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Replace `YOUR_API_KEY` with your actual Anthropic API key. This will save your API key securely in a configuration file, so you don't need to set it as an environment variable each time.
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
Once you've set up your API key, you can use the tool like this:
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
watcmd 'your command description'
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
For example:
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
watcmd 'to list all files in a directory'
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The tool will return an explanation of how to perform the task in a UNIX system.
|
|
53
|
+
|
|
54
|
+
You can also use the explicit query command:
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
watcmd query 'your command here'
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Development
|
|
61
|
+
|
|
62
|
+
If you want to contribute or modify the tool:
|
|
63
|
+
|
|
64
|
+
1. Clone this repository:
|
|
65
|
+
```
|
|
66
|
+
git clone https://github.com/alramalho/watcmd.git
|
|
67
|
+
cd watcmd
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
2. Install the package in editable mode:
|
|
71
|
+
```
|
|
72
|
+
pip install -e .
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
3. Make your changes and test them locally.
|
|
76
|
+
|
|
77
|
+
## Publishing to PyPI
|
|
78
|
+
|
|
79
|
+
To publish updates to PyPI:
|
|
80
|
+
|
|
81
|
+
1. Update the version in `pyproject.toml`
|
|
82
|
+
2. Build the package: `python -m build`
|
|
83
|
+
3. Upload to PyPI: `python -m twine upload dist/*`
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE.txt) file for details.
|
|
88
|
+
|
|
89
|
+
## Author
|
|
90
|
+
|
|
91
|
+
Alex Ramalho ([@alramalho](https://github.com/alramalho))
|
watcmd-0.1.2/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# watcmd
|
|
2
|
+
|
|
3
|
+
A CLI tool to get UNIX commands from text explanations using AI
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
You can install `watcmd` directly from PyPI:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
pip install watcmd
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Setup
|
|
14
|
+
|
|
15
|
+
After installation, you need to configure your Anthropic API key. You can do this by running:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
watcmd setup YOUR_API_KEY
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Replace `YOUR_API_KEY` with your actual Anthropic API key. This will save your API key securely in a configuration file, so you don't need to set it as an environment variable each time.
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
Once you've set up your API key, you can use the tool like this:
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
watcmd 'your command description'
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
For example:
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
watcmd 'to list all files in a directory'
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The tool will return an explanation of how to perform the task in a UNIX system.
|
|
38
|
+
|
|
39
|
+
You can also use the explicit query command:
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
watcmd query 'your command here'
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Development
|
|
46
|
+
|
|
47
|
+
If you want to contribute or modify the tool:
|
|
48
|
+
|
|
49
|
+
1. Clone this repository:
|
|
50
|
+
```
|
|
51
|
+
git clone https://github.com/alramalho/watcmd.git
|
|
52
|
+
cd watcmd
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
2. Install the package in editable mode:
|
|
56
|
+
```
|
|
57
|
+
pip install -e .
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
3. Make your changes and test them locally.
|
|
61
|
+
|
|
62
|
+
## Publishing to PyPI
|
|
63
|
+
|
|
64
|
+
To publish updates to PyPI:
|
|
65
|
+
|
|
66
|
+
1. Update the version in `pyproject.toml`
|
|
67
|
+
2. Build the package: `python -m build`
|
|
68
|
+
3. Upload to PyPI: `python -m twine upload dist/*`
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
|
|
72
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE.txt) file for details.
|
|
73
|
+
|
|
74
|
+
## Author
|
|
75
|
+
|
|
76
|
+
Alex Ramalho ([@alramalho](https://github.com/alramalho))
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "watcmd"
|
|
7
|
+
version = "0.1.2"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name="Alex Ramalho", email="alexandre.ramalho.1998@gmail.com" },
|
|
10
|
+
]
|
|
11
|
+
description = "c"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.7"
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
]
|
|
19
|
+
dependencies = [
|
|
20
|
+
"openai",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[project.urls]
|
|
24
|
+
"Homepage" = "https://github.com/alramalho/wat-cli"
|
|
25
|
+
"Bug Tracker" = "https://github.com/alramalho/wat-cli/issues"
|
|
26
|
+
|
|
27
|
+
[project.scripts]
|
|
28
|
+
watcmd = "watcmd:main"
|
|
29
|
+
|
|
30
|
+
[tool.hatch.build.targets.wheel]
|
|
31
|
+
packages = ["src/watcmd"]
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import configparser
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from openai import OpenAI
|
|
8
|
+
|
|
9
|
+
# ... (rest of the code remains the same)
|
|
10
|
+
|
|
11
|
+
CONFIG_DIR = Path.home() / '.config' / 'watcmd'
|
|
12
|
+
CONFIG_FILE = CONFIG_DIR / 'config.ini'
|
|
13
|
+
def get_api_key():
|
|
14
|
+
if CONFIG_FILE.exists():
|
|
15
|
+
config = configparser.ConfigParser()
|
|
16
|
+
config.read(CONFIG_FILE)
|
|
17
|
+
return config['DEFAULT']['api_key']
|
|
18
|
+
return os.environ.get('OPENAI_API_KEY')
|
|
19
|
+
|
|
20
|
+
def setup_config(api_key):
|
|
21
|
+
CONFIG_DIR.mkdir(parents=True, exist_ok=True)
|
|
22
|
+
config = configparser.ConfigParser()
|
|
23
|
+
config['DEFAULT'] = {'api_key': api_key}
|
|
24
|
+
with open(CONFIG_FILE, 'w') as configfile:
|
|
25
|
+
config.write(configfile)
|
|
26
|
+
print(f"API key saved to {CONFIG_FILE}")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def query_gpt4(prompt):
|
|
30
|
+
api_key = get_api_key()
|
|
31
|
+
if not api_key:
|
|
32
|
+
print("Error: OpenAI API key not found. Please set it using 'watcmd --setup YOUR_API_KEY'")
|
|
33
|
+
sys.exit(1)
|
|
34
|
+
|
|
35
|
+
client = OpenAI(api_key=get_api_key())
|
|
36
|
+
|
|
37
|
+
try:
|
|
38
|
+
response = client.chat.completions.create(model="gpt-4o",
|
|
39
|
+
messages=[
|
|
40
|
+
{"role": "system", "content": "You are a silent assitant that just outputs UNIX cli commands"},
|
|
41
|
+
{"role": "user", "content": f"what command for listing all files"},
|
|
42
|
+
{"role": "assistant", "content": f"ls -a"},
|
|
43
|
+
{"role": "user", "content": f"what command {prompt}"}
|
|
44
|
+
],
|
|
45
|
+
max_tokens=300)
|
|
46
|
+
return response.choices[0].message.content.strip()
|
|
47
|
+
except Exception as e:
|
|
48
|
+
print(f"Error: API request failed. {str(e)}")
|
|
49
|
+
sys.exit(1)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def main():
|
|
54
|
+
parser = argparse.ArgumentParser(description="Get UNIX commands from text explanations using AI")
|
|
55
|
+
parser.add_argument('--setup', metavar='API_KEY', help='Setup OpenAI API key')
|
|
56
|
+
parser.add_argument('query', nargs='*', help='The task description to get a UNIX command for')
|
|
57
|
+
args = parser.parse_args()
|
|
58
|
+
|
|
59
|
+
if args.setup:
|
|
60
|
+
setup_config(args.setup)
|
|
61
|
+
print("API key set successfully.")
|
|
62
|
+
elif args.query:
|
|
63
|
+
query = ' '.join(args.query)
|
|
64
|
+
suggested_command = query_gpt4(query)
|
|
65
|
+
print(suggested_command)
|
|
66
|
+
else:
|
|
67
|
+
parser.print_help()
|
|
68
|
+
|
|
69
|
+
if __name__ == "__main__":
|
|
70
|
+
main()
|