mirror of
https://github.com/kardolus/chatgpt-cli.git
synced 2024-09-08 23:15:00 +03:00
Update constructor implementation
This commit is contained in:
@@ -29,15 +29,7 @@ type Client struct {
|
||||
capacity int
|
||||
}
|
||||
|
||||
func New(caller http.Caller, rw history.Store, capacity int) *Client {
|
||||
return &Client{
|
||||
caller: caller,
|
||||
readWriter: rw,
|
||||
capacity: capacity,
|
||||
}
|
||||
}
|
||||
|
||||
func NewDefault(caller http.Caller, rw history.Store) *Client {
|
||||
func New(caller http.Caller, rw history.Store) *Client {
|
||||
return &Client{
|
||||
caller: caller,
|
||||
readWriter: rw,
|
||||
@@ -45,6 +37,11 @@ func NewDefault(caller http.Caller, rw history.Store) *Client {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) WithCapacity(capacity int) *Client {
|
||||
c.capacity = capacity
|
||||
return c
|
||||
}
|
||||
|
||||
// Query sends a query to the API and returns the response as a string.
|
||||
// It takes an input string as a parameter and returns a string containing
|
||||
// the API response or an error if there's any issue during the process.
|
||||
|
||||
@@ -36,7 +36,7 @@ func testClient(t *testing.T, when spec.G, it spec.S) {
|
||||
mockCtrl = gomock.NewController(t)
|
||||
mockCaller = NewMockCaller(mockCtrl)
|
||||
mockStore = NewMockStore(mockCtrl)
|
||||
subject = client.New(mockCaller, mockStore, 50)
|
||||
subject = client.New(mockCaller, mockStore).WithCapacity(50)
|
||||
})
|
||||
|
||||
it.After(func() {
|
||||
|
||||
@@ -52,7 +52,7 @@ func run(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
if clearHistory {
|
||||
historyHandler := history.NewDefault()
|
||||
historyHandler := history.New()
|
||||
err := historyHandler.Delete()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -72,7 +72,7 @@ func run(cmd *cobra.Command, args []string) error {
|
||||
if secret == "" {
|
||||
return errors.New("missing environment variable: " + secretEnv)
|
||||
}
|
||||
client := client.NewDefault(http.New().WithSecret(secret), history.NewDefault())
|
||||
client := client.New(http.New().WithSecret(secret), history.New())
|
||||
|
||||
// Check if there is input from the pipe (stdin)
|
||||
stat, _ := os.Stdin.Stat()
|
||||
|
||||
@@ -21,17 +21,16 @@ type FileIO struct {
|
||||
historyFilePath string
|
||||
}
|
||||
|
||||
func NewDefault() *FileIO {
|
||||
func New() *FileIO {
|
||||
path, _ := getPath()
|
||||
return &FileIO{
|
||||
historyFilePath: path,
|
||||
}
|
||||
}
|
||||
|
||||
func New(historyFilePath string) *FileIO {
|
||||
return &FileIO{
|
||||
historyFilePath: historyFilePath,
|
||||
}
|
||||
func (f *FileIO) WithHistory(historyFilePath string) *FileIO {
|
||||
f.historyFilePath = historyFilePath
|
||||
return f
|
||||
}
|
||||
|
||||
func (f *FileIO) Delete() error {
|
||||
|
||||
@@ -39,7 +39,7 @@ func testIntegration(t *testing.T, when spec.G, it spec.S) {
|
||||
|
||||
tmpFile.Close()
|
||||
|
||||
fileIO = history.New(tmpFile.Name())
|
||||
fileIO = history.New().WithHistory(tmpFile.Name())
|
||||
|
||||
messages = []types.Message{
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user