From 58cadf5420b5635b1b2cf6d06493549c961f91a0 Mon Sep 17 00:00:00 2001 From: Marcel Kloubert Date: Tue, 25 Jul 2023 21:34:35 +0200 Subject: [PATCH] change input order --- CHANGELOG.md | 7 +++++++ README.md | 6 +++--- utils/utils.go | 27 +++++++++++++-------------- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f7c5ae..17afbad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log (e.GPT) +## 0.6.0 + +- **BREAKING CHANGE**: changed input order to: + 1. arguments + 2. editor + 3. STDIN + ## 0.5.0 - implement `ui` command, which open a local UI, thanks to [jbonot](https://github.com/egomobile/e-gpt/issues/2) diff --git a/README.md b/README.md index c828734..584da20 100644 --- a/README.md +++ b/README.md @@ -300,11 +300,11 @@ You have the following sources for input data: 1. One or more non-flag command line arguments. All will be concatenate and seperated by space to one string. - Example: `egpt ask who is bill gates` -2. The [STDIN](https://en.wikipedia.org/wiki/Standard_streams): +2. The standard editor: + - Example: `egpt ask summarize the following text --editor` +3. The [STDIN](https://en.wikipedia.org/wiki/Standard_streams): - Example #1: `egpt ask "please summarize" < ./long-text.txt` - Example #2: `curl -sSL "https://raw.githubusercontent.com/egomobile/e-gpt/main/LICENSE" | ./egpt ask summarize the following text` -3. The standard editor: - - Example: `egpt ask summarize the following text --editor` You can combine all kind of inputs. All texts will be concatenated in the given order and seperated by space to one string. diff --git a/utils/utils.go b/utils/utils.go index e17974e..c6d3cae 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -22,7 +22,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "net/url" "os" @@ -212,18 +211,6 @@ func GetInput(args []string, openEditor bool) (string, error) { addPart(strings.Join(args, " ")) - stdinStat, _ := os.Stdin.Stat() - if (stdinStat.Mode() & os.ModeCharDevice) == 0 { - scanner := bufio.NewScanner(os.Stdin) - - temp := "" - for scanner.Scan() { - temp += scanner.Text() - } - - addPart(temp) - } - if openEditor { // at last: try editor @@ -263,6 +250,18 @@ func GetInput(args []string, openEditor bool) (string, error) { addPart(string(tmpData)) } + stdinStat, _ := os.Stdin.Stat() + if (stdinStat.Mode() & os.ModeCharDevice) == 0 { + scanner := bufio.NewScanner(os.Stdin) + + temp := "" + for scanner.Scan() { + temp += scanner.Text() + } + + addPart(temp) + } + return strings.TrimSpace(strings.Join(parts, " ")), nil } @@ -354,7 +353,7 @@ func GetSystemPrompt() (string, bool, error) { return "", isCustom, err } - data, err := ioutil.ReadFile(filePath) + data, err := os.ReadFile(filePath) if err != nil { return "", isCustom, err }