Skip to content

Commit

Permalink
feat(text) : add -u parameter to add url
Browse files Browse the repository at this point in the history
  • Loading branch information
LordPax committed Oct 13, 2024
1 parent 07ac8bc commit fb7010e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Added

* Add parameter -u for text command to web page content

### Changed

* Parameter -f in text command accept image file (only for claude sdk)
Expand Down
24 changes: 24 additions & 0 deletions commands/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,30 @@ func textFlags() []cli.Flag {
return nil
},
},
&cli.StringSliceFlag{
Name: "url",
Aliases: []string{"u"},
Usage: l.Get("text-url-usage"),
Category: "text",
Action: func(c *cli.Context, urls []string) error {
text := sdk.GetSdkText()

for _, url := range urls {
f, err := utils.GetFileFromUrl(url)
if err != nil {
return err
}

if len(f) == 0 {
return fmt.Errorf(l.Get("empty-file"), url)
}

text.AppendHistory("system", string(f))
}

return nil
},
},
&cli.BoolFlag{
Name: "clear",
Aliases: []string{"c"},
Expand Down
1 change: 1 addition & 0 deletions lang/en.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var EN_STRINGS = LangString{
"translate-input": "(\"exit\" to quit) " + utils.Blue + "> " + utils.Reset,
"text-list-history-usage": "List history",
"text-list-history-name-usage": "List history names",
"text-url-usage": "URL of a web page",
"type-required": "Type is required",
"api-key-required": "API key is required",
"empty-file": "File \"%s\" is empty",
Expand Down
1 change: 1 addition & 0 deletions lang/fr.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var FR_STRINGS = LangString{
"translate-input": "(\"exit\" pour quitter) " + utils.Blue + "> " + utils.Reset,
"text-list-history-usage": "Lister l'historique",
"text-list-history-name-usage": "Lister les noms d'historique",
"text-url-usage": "URL d'une page web",
"type-required": "Le type est requis",
"api-key-required": "La clé API est requise",
"empty-file": "Le fichier \"%s\" est vide",
Expand Down
11 changes: 11 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package utils

import (
"bytes"
"io"
"net/http"
"os"
"strings"
Expand Down Expand Up @@ -80,3 +81,13 @@ func IsFileType(buf []byte, fileType []string) string {
}
return ""
}

func GetFileFromUrl(url string) ([]byte, error) {
resp, err := http.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()

return io.ReadAll(resp.Body)
}

0 comments on commit fb7010e

Please sign in to comment.