-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
connect: add initial custom evaler support
Add support for customizing the way user input is processed. The `--evaler` option is added to specify the Lua code, which accepts `cmd` var containing user input for current connection. The evaler Lua code can be loaded from file. Autocompletion is disabled if custom evaler is set.
- Loading branch information
Showing
11 changed files
with
184 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package luabody | ||
|
||
import ( | ||
_ "embed" | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/tarantool/cartridge-cli/cli/templates" | ||
) | ||
|
||
//go:embed eval_func_body.lua | ||
var evalFuncBody string | ||
|
||
//go:embed get_suggestions_func_body.lua | ||
var getSuggestionsFuncBody string | ||
|
||
// GetEvalFuncBody returns lua code of eval func. | ||
func GetEvalFuncBody(evaler string) (string, error) { | ||
mapping := map[string]string{} | ||
if len(evaler) != 0 { | ||
if strings.HasPrefix(evaler, "@") { | ||
evalerFileBytes, err := os.ReadFile(strings.TrimPrefix(evaler, "@")) | ||
if err != nil { | ||
return "", fmt.Errorf("failed to read the evaler file: %s", err) | ||
} | ||
mapping["evaler"] = string(evalerFileBytes) | ||
} else { | ||
mapping["evaler"] = evaler | ||
} | ||
} | ||
|
||
return templates.GetTemplatedStr(&evalFuncBody, mapping) | ||
} | ||
|
||
// GetEvalFuncBody returns lua code for completions. | ||
func GetSuggestionsFuncBody() string { | ||
return getSuggestionsFuncBody | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters