Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
change input order
Browse files Browse the repository at this point in the history
  • Loading branch information
mkloubert committed Jul 25, 2023
1 parent c486190 commit 58cadf5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
27 changes: 13 additions & 14 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 58cadf5

Please sign in to comment.