Compare commits

...

15 Commits

Author SHA1 Message Date
asrul10
ae90ef6cfb Merge pull request #8 from asrul10/feature/regenerate-gpt
Add a feature to regenerate the result and some minor improvements
2023-04-09 10:56:43 +07:00
asrul10
7f81b1942b style: update version 2023-04-09 10:54:35 +07:00
asrul10
dafcaaff0f docs: update example result 2023-04-09 10:53:11 +07:00
asrul10
fbb68d2a28 feat: add regenerate options 2023-04-09 10:51:26 +07:00
asrul10
2d6fef23aa chore: set default options to (N)o execute 2023-04-09 10:33:53 +07:00
asrul10
432bfc61db feat: add example usage if there is no option 2023-04-09 10:30:13 +07:00
asrul10
0e50c8ec04 feat: remove borders to make it easy to copy 2023-04-09 10:25:50 +07:00
asrul10
148e1d9420 fix: box result 2023-03-25 22:26:38 +07:00
asrul10
952eee1a29 docs: fix link 2023-03-12 16:20:23 +07:00
asrul10
c2619a2864 docs: add executable link 2023-03-12 16:13:01 +07:00
asrul10
b1166a724d Merge pull request #1 from asrul10/workflow
Add github actions for release
2023-03-12 16:04:27 +07:00
asrul10
c6b1474117 chore: add github actions 2023-03-12 16:01:18 +07:00
asrul10
b04f7016b8 fix: remove precompiled file 2023-03-12 14:36:12 +07:00
asrul10
4f52b5bbad docs: add LICENSE 2023-03-12 06:48:21 +07:00
asrul10
dce4360043 fix: blocking loading when input api key 2023-03-12 06:27:03 +07:00
8 changed files with 139 additions and 40 deletions

31
.github/workflows/release.yaml vendored Normal file
View File

@@ -0,0 +1,31 @@
name: basebuild
on:
pull_request:
push:
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '>=1.18.0'
- name: Run tests
run: go test ./...
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
with:
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}

2
.gitignore vendored
View File

@@ -8,4 +8,4 @@
go.work go.work
*.log *.log
lcg lcg
dist/

33
.goreleaser.yaml Normal file
View File

@@ -0,0 +1,33 @@
archives:
- format: tar.gz
builds:
- binary: lcg
env:
- CGO_ENABLED=0
goarch:
- amd64
- arm64
- arm
goos:
- linux
- darwin
changelog:
filters:
exclude:
- '^docs:'
- '^test:'
sort: asc
checksum:
name_template: 'checksums.txt'
release:
draft: true
snapshot:
name_template: "{{ incpatch .Version }}-next"
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

21
LICENSE Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023 asrul10
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -11,15 +11,17 @@ Build from source
> ln -s ~/.linux-command-gpt/lcg ~/.local/bin > ln -s ~/.linux-command-gpt/lcg ~/.local/bin
``` ```
Or you can [download lcg executable file](https://github.com/asrul10/linux-command-gpt/releases)
### Example Usage ### Example Usage
```bash ```bash
> lcg I want to extract file linux-command-gpt.tar.gz > 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

0
go.sum Normal file
View File

Binary file not shown.

80
main.go
View File

@@ -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
} }
s := time.Now() c := "R"
done := make(chan bool) r := ""
go func() { elapsed := 0.0
loadingChars := []rune{'-', '\\', '|', '/'} for c == "R" || c == "r" {
i := 0 r, elapsed = getCommand(gpt3, cmd)
for { c = "N"
select { fmt.Printf("Completed in %v seconds\n\n", elapsed)
case <-done: fmt.Println(r)
fmt.Printf("\r") fmt.Print("\nDo you want to (e)xecute, (r)egenerate, or take (N)o action on the command? (e/r/N): ")
return fmt.Scanln(&c)
default: if c == "N" || c == "n" {
fmt.Printf("\rLoading %c", loadingChars[i]) return
i = (i + 1) % len(loadingChars)
time.Sleep(30 * time.Millisecond)
}
} }
}() }
gpt3.InitKey()
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()