-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
99 lines (83 loc) · 2.51 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"fmt"
"os"
"path"
"strings"
"github.com/go-git/go-git/v5"
openai "github.com/sashabaranov/go-openai"
"github.com/spf13/cobra"
)
var (
apiKey = os.Getenv("OPENAI_API_KEY")
client *openai.Client
systemCard string
preTaskCard string
postTaskCard string
)
// Define a root command
var rootCmd = &cobra.Command{
Use: "juno",
Short: "Juno is a simple CLI app",
}
// Define a clone command
// Define a clone command
var cloneCmd = &cobra.Command{
Use: "clone [url]",
Short: "Clone a git repository",
Args: cobra.ExactArgs(1), // Require exactly one argument
Run: func(cmd *cobra.Command, args []string) {
// Get the repository URL from the argument
url := args[0]
// Get the current working directory
dir, err := os.Getwd()
if err != nil {
fmt.Println("Error getting current working directory:", err)
return
}
// Create a folder in the current working directory with the name of the repository
repoName := path.Base(url) // Get the last element of the URL
repoName = strings.TrimSuffix(repoName, ".git") // Remove the .git suffix if any
dir = path.Join(dir, repoName) // Join the directory and the repository name
err = os.Mkdir(dir, 0755) // Create the folder with read-write-execute permissions for owner and read-execute permissions for group and others
if err != nil {
fmt.Println("Error creating folder:", err)
return
}
fmt.Println("Cloning", url, "to", dir)
repo, err := git.PlainClone(dir, false, &git.CloneOptions{
URL: url,
Progress: os.Stdout,
})
if err != nil {
fmt.Println("Error cloning repository:", err)
return
}
fmt.Println("Cloned successfully:", repo)
},
}
// Define a do command
// Define a do command
var doCmd = &cobra.Command{
Use: "do [task]",
Short: "Ask Juno to perform a task",
Args: cobra.ExactArgs(1), // Require exactly one argument
Run: func(cmd *cobra.Command, args []string) {
// Get the task from the argument
task := args[0]
// Print the command
fmt.Println("Task:", task)
executeTask(client, systemCard, populateSkills(preTaskCard)+"\n"+task+"\n"+postTaskCard)
},
}
func main() {
systemCard = readFile("cards/00-system-card.txt")
preTaskCard = readFile("cards/01-pre-task.txt")
postTaskCard = readFile("cards/02-post-task.txt")
client = openai.NewClient(apiKey)
// Add the sub commands to the root command
rootCmd.AddCommand(cloneCmd)
rootCmd.AddCommand(doCmd)
// Execute the root command
rootCmd.Execute()
}