mirror of
https://github.com/Direct-Dev-Ru/go-lcg.git
synced 2025-11-16 01:29:55 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d11017d792 | ||
|
|
1c4113d0c2 |
@@ -30,8 +30,9 @@ To use the "copy to clipboard" feature, you need to install either the `xclip` o
|
|||||||
```bash
|
```bash
|
||||||
> lcg [options]
|
> lcg [options]
|
||||||
|
|
||||||
--help output usage information
|
--help -h output usage information
|
||||||
--version output the version number
|
--version -v output the version number
|
||||||
--update-key update the API key
|
--file -f read command from file
|
||||||
--delete-key delete the API key
|
--update-key -u update the API key
|
||||||
|
--delete-key -d delete the API key
|
||||||
```
|
```
|
||||||
|
|||||||
30
main.go
30
main.go
@@ -9,6 +9,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/asrul/linux-command-gpt/gpt"
|
"github.com/asrul/linux-command-gpt/gpt"
|
||||||
|
"github.com/asrul/linux-command-gpt/reader"
|
||||||
"github.com/atotto/clipboard"
|
"github.com/atotto/clipboard"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -26,15 +27,17 @@ const (
|
|||||||
|
|
||||||
Usage: lcg [options]
|
Usage: lcg [options]
|
||||||
|
|
||||||
--help output usage information
|
--help -h output usage information
|
||||||
--version output the version number
|
--version -v output the version number
|
||||||
--update-key update the API key
|
--file -f read command from file
|
||||||
--delete-key delete the API key
|
--update-key -u update the API key
|
||||||
|
--delete-key -d delete the API key
|
||||||
|
|
||||||
Example Usage: lcg I want to extract linux-command-gpt.tar.gz file
|
Example Usage: lcg I want to extract linux-command-gpt.tar.gz file
|
||||||
|
Example Usage: lcg --file /path/to/file.json I want to print object questions with jq
|
||||||
`
|
`
|
||||||
|
|
||||||
VERSION = "0.1.3"
|
VERSION = "0.2.1"
|
||||||
CMD_HELP = 100
|
CMD_HELP = 100
|
||||||
CMD_VERSION = 101
|
CMD_VERSION = 101
|
||||||
CMD_UPDATE = 102
|
CMD_UPDATE = 102
|
||||||
@@ -97,9 +100,24 @@ func main() {
|
|||||||
|
|
||||||
args := os.Args
|
args := os.Args
|
||||||
cmd := ""
|
cmd := ""
|
||||||
|
file := ""
|
||||||
if len(args) > 1 {
|
if len(args) > 1 {
|
||||||
cmd = strings.Join(args[1:], " ")
|
start := 1
|
||||||
|
if args[1] == "--file" || args[1] == "-f" {
|
||||||
|
file = args[2]
|
||||||
|
start = 3
|
||||||
|
}
|
||||||
|
cmd = strings.Join(args[start:], " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if file != "" {
|
||||||
|
err := reader.FileToPrompt(&cmd, file)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
h := handleCommand(cmd)
|
h := handleCommand(cmd)
|
||||||
|
|
||||||
if h == CMD_HELP {
|
if h == CMD_HELP {
|
||||||
|
|||||||
24
reader/file.go
Normal file
24
reader/file.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package reader
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func FileToPrompt(cmd *string, filePath string) error {
|
||||||
|
f, err := os.Open(filePath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
reader := bufio.NewReader(f)
|
||||||
|
*cmd = *cmd + "\nFile path: " + filePath + "\n"
|
||||||
|
for {
|
||||||
|
line, err := reader.ReadString('\n')
|
||||||
|
if err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
*cmd = *cmd + "\n" + line
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user