mirror of
https://github.com/Direct-Dev-Ru/go-lcg.git
synced 2025-11-17 01:59:55 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ae90ef6cfb | ||
|
|
7f81b1942b | ||
|
|
dafcaaff0f | ||
|
|
fbb68d2a28 | ||
|
|
2d6fef23aa | ||
|
|
432bfc61db | ||
|
|
0e50c8ec04 | ||
|
|
148e1d9420 |
@@ -18,10 +18,10 @@ Or you can [download lcg executable file](https://github.com/asrul10/linux-comma
|
|||||||
```bash
|
```bash
|
||||||
> lcg I want to extract linux-command-gpt.tar.gz file
|
> lcg I want to extract linux-command-gpt.tar.gz file
|
||||||
Completed in 0.92 seconds
|
Completed in 0.92 seconds
|
||||||
┌────────────────────────────────────┐
|
|
||||||
│ tar -xvzf linux-command-gpt.tar.gz │
|
tar -xvzf linux-command-gpt.tar.gz
|
||||||
└────────────────────────────────────┘
|
|
||||||
Are you sure you want to execute the command? (Y/n):
|
Do you want to (e)xecute, (r)egenerate, or take (N)o action on the command? (e/r/N):
|
||||||
```
|
```
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|||||||
80
main.go
80
main.go
@@ -31,9 +31,10 @@ Usage: lcg [options]
|
|||||||
--update-key update the API key
|
--update-key update the API key
|
||||||
--delete-key delete the API key
|
--delete-key delete the API key
|
||||||
|
|
||||||
|
Example Usage: lcg I want to extract linux-command-gpt.tar.gz file
|
||||||
`
|
`
|
||||||
|
|
||||||
VERSION = "0.1.0"
|
VERSION = "0.1.3"
|
||||||
CMD_HELP = 100
|
CMD_HELP = 100
|
||||||
CMD_VERSION = 101
|
CMD_VERSION = 101
|
||||||
CMD_UPDATE = 102
|
CMD_UPDATE = 102
|
||||||
@@ -57,6 +58,37 @@ func handleCommand(cmd string) int {
|
|||||||
return CMD_COMPLETION
|
return CMD_COMPLETION
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getCommand(gpt3 gpt.Gpt3, cmd string) (string, float64) {
|
||||||
|
gpt3.InitKey()
|
||||||
|
s := time.Now()
|
||||||
|
done := make(chan bool)
|
||||||
|
go func() {
|
||||||
|
loadingChars := []rune{'-', '\\', '|', '/'}
|
||||||
|
i := 0
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-done:
|
||||||
|
fmt.Printf("\r")
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
fmt.Printf("\rLoading %c", loadingChars[i])
|
||||||
|
i = (i + 1) % len(loadingChars)
|
||||||
|
time.Sleep(30 * time.Millisecond)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
r := gpt3.Completions(cmd)
|
||||||
|
done <- true
|
||||||
|
elapsed := time.Since(s).Seconds()
|
||||||
|
elapsed = math.Round(elapsed*100) / 100
|
||||||
|
|
||||||
|
if r == "" {
|
||||||
|
return "", elapsed
|
||||||
|
}
|
||||||
|
return r, elapsed
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
currentUser, err := user.Current()
|
currentUser, err := user.Current()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -98,44 +130,24 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
gpt3.InitKey()
|
c := "R"
|
||||||
s := time.Now()
|
r := ""
|
||||||
done := make(chan bool)
|
elapsed := 0.0
|
||||||
go func() {
|
for c == "R" || c == "r" {
|
||||||
loadingChars := []rune{'-', '\\', '|', '/'}
|
r, elapsed = getCommand(gpt3, cmd)
|
||||||
i := 0
|
c = "N"
|
||||||
for {
|
fmt.Printf("Completed in %v seconds\n\n", elapsed)
|
||||||
select {
|
fmt.Println(r)
|
||||||
case <-done:
|
fmt.Print("\nDo you want to (e)xecute, (r)egenerate, or take (N)o action on the command? (e/r/N): ")
|
||||||
fmt.Printf("\r")
|
fmt.Scanln(&c)
|
||||||
return
|
if c == "N" || c == "n" {
|
||||||
default:
|
return
|
||||||
fmt.Printf("\rLoading %c", loadingChars[i])
|
|
||||||
i = (i + 1) % len(loadingChars)
|
|
||||||
time.Sleep(30 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}()
|
}
|
||||||
|
|
||||||
r := gpt3.Completions(cmd)
|
|
||||||
done <- true
|
|
||||||
if r == "" {
|
if r == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c := "Y"
|
|
||||||
elapsed := time.Since(s).Seconds()
|
|
||||||
elapsed = math.Round(elapsed*100) / 100
|
|
||||||
fmt.Printf("Completed in %v seconds\n", elapsed)
|
|
||||||
fmt.Printf("┌%s┐\n", strings.Repeat("─", len(r)+2))
|
|
||||||
fmt.Printf("│ %s │\n", r)
|
|
||||||
fmt.Printf("└%s┘\n", strings.Repeat("─", len(r)+2))
|
|
||||||
fmt.Print("Are you sure you want to execute the command? (Y/n): ")
|
|
||||||
fmt.Scanln(&c)
|
|
||||||
if c != "Y" && c != "y" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
cmsplit := strings.Split(r, " ")
|
cmsplit := strings.Split(r, " ")
|
||||||
cm := exec.Command(cmsplit[0], cmsplit[1:]...)
|
cm := exec.Command(cmsplit[0], cmsplit[1:]...)
|
||||||
out, err := cm.Output()
|
out, err := cm.Output()
|
||||||
|
|||||||
Reference in New Issue
Block a user