Skip to content

Commit 74a62e2

Browse files
committed
Refactor Makefile, update README, and modify main.go for improved functionality
1 parent dcbe6d8 commit 74a62e2

4 files changed

Lines changed: 127 additions & 59 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ run:
44
go run *.go
55

66
build:
7-
go build -o gocommit
7+
go build -o gocli

README.md

Lines changed: 109 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,142 @@
1-
📚 README
2-
================
1+
# 📚 README
32

4-
👋 Introduction
5-
---------------
3+
## 👋 Introduction
64

75
This project is a Go-based command-line interface (CLI) that utilizes the Groq API to provide a simple and efficient way to generate descriptive commit messages and chat responses. 🤖
86

9-
🚀 Project Setup
10-
-----------------
7+
## 🚀 Project Setup
8+
9+
### Prerequisites
10+
11+
1. **Install Go**: Download and install Go from the official website: https://go.dev/dl/ 📦
12+
13+
2. **Install Make**:
14+
- **Windows**:
15+
```bash
16+
# Using Chocolatey
17+
choco install make
18+
# or using Scoop
19+
scoop install make
20+
```
21+
- **macOS**:
22+
```bash
23+
# Using Homebrew
24+
brew install make
25+
```
26+
- **Linux**:
27+
```bash
28+
# Debian/Ubuntu
29+
sudo apt-get install make
30+
# Fedora
31+
sudo dnf install make
32+
# CentOS/RHEL
33+
sudo yum install make
34+
```
35+
36+
3. **Get the Repository**: Clone the repository:
37+
```bash
38+
git clone https://github.com/NevroHelios/cliagent.git
39+
```
40+
41+
4. **Install Dependencies**:
42+
```bash
43+
go get -u github.com/joho/godotenv
44+
go get -u github.com/kelvins/go-uber-zap
45+
go get -u github.com/urfave/cli/v2
46+
```
47+
48+
### Building the Project
49+
50+
#### Development Build (using .env)
51+
1. Create a `.env` file in the project root:
52+
```makefile
53+
GROQ_API_KEY=your_api_key_here
54+
```
55+
2. Build the project:
56+
```bash
57+
go build -o gocli
58+
```
59+
60+
#### Production Build (embedded API key)
61+
Build the project with your API key embedded:
1162

12-
To set up the project, follow these steps:
13-
14-
1. **Install Go**: Make sure you have Go installed on your system. You can download it from the official Go website: https://go.dev/dl/ 📦
15-
2. **Get the Repository**: Clone the repository using the following command:
1663
```bash
17-
git clone https://github.com/NevroHelios/cliagent.git
64+
# Linux/macOS
65+
go build -ldflags "-X main.GROQ_API_KEY=your-api-key-here" -o gocli
66+
67+
# Windows (PowerShell)
68+
go build -ldflags "-X main.GROQ_API_KEY=your-api-key-here" -o gocli.exe
1869
```
19-
3. **Install Dependencies**: Install the required dependencies using the following command:
70+
71+
Alternatively, use environment variable:
2072
```bash
21-
go get -u github.com/joho/godotenv
22-
go get -u github.com/kelvins/go-uber-zap
23-
go get -u github.com/urfave/cli/v2
24-
```
25-
4. **Create a `.env` File**: Create a new file named `.env` in the root of the project and add your Groq API key:
26-
```makefile
27-
GROQ_API_KEY=your_api_key_here
73+
# Linux/macOS
74+
export GROQ_API_KEY=your-api-key-here
75+
go build -ldflags "-X main.GROQ_API_KEY=$GROQ_API_KEY" -o gocli
76+
77+
# Windows (PowerShell)
78+
$env:GROQ_API_KEY="your-api-key-here"
79+
go build -ldflags "-X main.GROQ_API_KEY=$env:GROQ_API_KEY" -o gocli.exe
2880
```
29-
🏃‍♂️ Running the Project
30-
-------------------------
3181

32-
To run the project, follow these steps:
82+
### Creating a Symlink (Optional)
3383

34-
1. **Navigate to the Project Directory**: Navigate to the project directory using the following command:
35-
```bash
36-
cd cliagent
37-
```
38-
2. **Build the Project**: Build the project using the following command:
39-
```bash
40-
go build -o gocli
41-
```
42-
3. **Run the Project**: Run the project using the following command:
43-
```bash
44-
./gocli
45-
```
46-
4. **Follow the Prompts**: Follow the prompts to select a model, enter a query, and generate a response. 🤔
84+
To run the CLI from any directory:
85+
86+
- **Windows** (Run PowerShell as Administrator):
87+
```powershell
88+
New-Item -ItemType SymbolicLink -Path "C:\Windows\System32\gocli.exe" -Target "$pwd\gocli.exe"
89+
```
90+
91+
- **Linux/macOS**:
92+
```bash
93+
sudo ln -s "$(pwd)/gocli" /usr/local/bin/gocli
94+
```
95+
96+
## 🏃‍♂️ Running the Project
97+
98+
1. **Navigate to the Project Directory**:
99+
```bash
100+
cd cliagent
101+
```
47102

48-
📝 Generating Commit Messages
49-
-----------------------------
103+
2. **Run the Project**:
104+
```bash
105+
./gocli
106+
# If symlinked, simply run from anywhere:
107+
gocli
108+
```
50109

51-
To generate a descriptive commit message, follow these steps:
110+
3. **Follow the Prompts**: Follow the prompts to select a model, enter a query, and generate a response. 🤔
111+
112+
## 📝 Generating Commit Messages
52113

53114
1. **Select the "Commit" Option**: Select the "Commit" option from the main menu.
54115
2. **Select a Model**: Enter a query to generate a commit message.
55116
3. **Generate the Commit Message**: The project will generate a descriptive commit message with your selected Model. 📝
56117

57-
🤖 Generating Chat Responses
58-
-----------------------------
59-
60-
To generate a chat response, follow these steps:
118+
## 🤖 Generating Chat Responses
61119

62120
1. **Select the "Chat" Option**: Select the "Chat" option from the main menu.
63121
2. **Enter a Query**: Enter a query to generate a chat response.
64122
3. **Generate the Chat Response**: The project will generate a chat response based on your query. 💬
65123

66-
👍 Contributing
67-
-----------------
124+
## 👍 Contributing
68125

69126
If you'd like to contribute to the project, please follow these steps:
70127
71128
1. **Fork the Repository**: Fork the repository using the GitHub fork button.
72129
2. **Make Changes**: Make changes to the code and commit them using a descriptive commit message.
73130
3. **Create a Pull Request**: Create a pull request to merge your changes into the main repository. 🚀
74131
75-
🙏 Acknowledgments
76-
------------------
132+
## ⚠️ Security Note
133+
134+
When building with an embedded API key:
135+
- Never commit the build command containing your API key
136+
- Consider using environment variables for the build process
137+
- Keep your compiled binary secure as it contains your API key
138+
139+
## 🙏 Acknowledgments
77140
78141
This project utilizes the following libraries and frameworks:
79142

gocli.exe

10.2 MB
Binary file not shown.

main.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var (
2121
AvailableModels []string
2222
ModelsMapped map[string]interface{}
2323
modelOptions []huh.Option[string]
24+
GROQ_API_KEY string
2425
)
2526

2627
func loadHuhModelOption(API_KEY string) {
@@ -34,12 +35,16 @@ func loadHuhModelOption(API_KEY string) {
3435

3536
func main() {
3637

37-
// load the env
38-
err := godotenv.Load("/home/shrek/Desktop/projects/gocli/.env")
39-
if err != nil {
40-
fmt.Println("Error loading .env file", err)
38+
// if api not provided during build time
39+
if GROQ_API_KEY == "" {
40+
// load the env
41+
err := godotenv.Load("~/$HOME/Desktop/projects/gocli/.env")
42+
if err != nil {
43+
fmt.Println("Error loading .env file", err)
44+
return
45+
}
46+
GROQ_API_KEY = os.Getenv("GROQ_API_KEY")
4147
}
42-
GROQ_API_KEY := os.Getenv("GROQ_API_KEY")
4348

4449
// check if the user wats to chat or commit
4550
var purpose string = "commit"
@@ -51,7 +56,7 @@ func main() {
5156
).
5257
Value(&purpose)
5358

54-
err = purForm.Run()
59+
err := purForm.Run()
5560
if err != nil {
5661
fmt.Println(err)
5762
return
@@ -133,13 +138,13 @@ func main() {
133138
fmt.Println(res)
134139

135140
// copy to clipboard
136-
if purpose == "commit" {
137-
clipErr := clipboard.WriteAll(res)
138-
if clipErr != nil {
139-
fmt.Println("failed to copy ", clipErr)
140-
return
141-
}
141+
// if purpose == "commit" {
142+
clipErr := clipboard.WriteAll(res)
143+
if clipErr != nil {
144+
fmt.Println("failed to copy ", clipErr)
145+
return
142146
}
147+
// }
143148
} else {
144149
fmt.Println("yare yare! Prompt is empty!!!")
145150
}

0 commit comments

Comments
 (0)