Class ToolsEdit

java.lang.Object
ai.wanaku.cli.main.commands.BaseCommand
ai.wanaku.cli.main.commands.tools.ToolsEdit
All Implemented Interfaces:
Callable<Integer>

public class ToolsEdit extends BaseCommand
  • Field Details

    • host

      protected String 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:
      doCall in class BaseCommand
      Returns:
      EXIT_OK; if the operation was successful, 1 otherwise.
      Throws:
      Exception - if an error occurs during the operation.
      IOException
    • confirm

      public boolean confirm(org.jline.terminal.Terminal terminal, ToolReference tool) throws IOException
      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.