Class ToolsEdit
java.lang.Object
ai.wanaku.cli.main.commands.BaseCommand
ai.wanaku.cli.main.commands.tools.ToolsEdit
-
Field Summary
FieldsFields inherited from class ai.wanaku.cli.main.commands.BaseCommand
EXIT_ERROR, EXIT_OK -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanconfirm(org.jline.terminal.Terminal terminal, ToolReference tool) Prompts the user for confirmation to update the specified tool.doCall(org.jline.terminal.Terminal terminal, WanakuPrinter printer) This method is the entry point for the `edit` command.Runs the Nano editor to allow the user to modify the selected tool definition.selectTool(org.jline.terminal.Terminal terminal, List<ToolReference> list) Presents a list of available tools to the user and allows them to select one.Methods inherited from class ai.wanaku.cli.main.commands.BaseCommand
call, initService
-
Field Details
-
host
-
-
Constructor Details
-
ToolsEdit
public ToolsEdit()
-
-
Method Details
-
doCall
public Integer doCall(org.jline.terminal.Terminal terminal, WanakuPrinter printer) throws IOException, Exception This method is the entry point for the `edit` command. It allows users to edit a tool's definition either by providing the tool name as a parameter or by selecting from a list of registered tools. It uses the Nano editor for modifying the tool definition and prompts for confirmation before saving.- Specified by:
doCallin classBaseCommand- Returns:
- EXIT_OK; if the operation was successful, 1 otherwise.
- Throws:
Exception- if an error occurs during the operation.IOException
-
confirm
Prompts the user for confirmation to update the specified tool.- Parameters:
terminal- The JLine terminal instance.tool- The ToolReference object to be updated.- Returns:
- true if the user confirms the update, false otherwise.
- Throws:
IOException- if an I/O error occurs during the prompt.
-
edit
public String edit(org.jline.terminal.Terminal terminal, String toolString, String toolName) throws IOException Runs the Nano editor to allow the user to modify the selected tool definition. The tool definition is written to a temporary file, edited using Nano, and then the modified content is read back.- Parameters:
terminal- The JLine terminal instance.toolString- The initial JSON string representation of the tool.toolName- The name of the tool being edited.- Returns:
- The modified content of the tool definition as a String.
- Throws:
IOException- if an I/O error occurs during file operations or running Nano.
-
selectTool
public ToolReference selectTool(org.jline.terminal.Terminal terminal, List<ToolReference> list) throws IOException Presents a list of available tools to the user and allows them to select one. The list is formatted for better readability in the terminal.- Parameters:
terminal- The JLine terminal instance.list- A list of ToolReference objects to choose from.- Returns:
- The selected ToolReference object.
- Throws:
IOException- if an I/O error occurs during the prompt.
-