Class: Aiko::Tools::ListFiles

Inherits:
Base
  • Object
show all
Defined in:
lib/aiko/tools/list_files.rb

Constant Summary collapse

EXCLUDED_DIRS =
%w[.git node_modules vendor tmp].freeze
MAX_ENTRIES =
1_000

Constants inherited from Base

Base::OUTPUT_LIMIT

Instance Method Summary collapse

Methods inherited from Base

#approval_message, #initialize, #requires_approval?

Constructor Details

This class inherits a constructor from Aiko::Tools::Base

Instance Method Details

#call(arguments) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/aiko/tools/list_files.rb', line 36

def call(arguments)
  base = resolve_path(arguments["path"] || ".")
  return "Error: no such directory: #{arguments["path"]}" unless File.directory?(base)

  entries = arguments["recursive"] ? collect_recursive(base) : collect_flat(base)
  entries.sort!
  return "(empty)" if entries.empty?

  if entries.size > MAX_ENTRIES
    entries = entries.first(MAX_ENTRIES)
    entries << "[#{MAX_ENTRIES}エントリを超えたため省略しました]"
  end
  truncate(entries.join("\n"))
end

#descriptionObject



13
14
15
16
17
# File 'lib/aiko/tools/list_files.rb', line 13

def description
  "List files and directories. Directories have a trailing '/'. " \
    "Set recursive to true to list the whole tree (hidden files and " \
    "directories like .git/node_modules are skipped when recursive)."
end

#input_schemaObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/aiko/tools/list_files.rb', line 19

def input_schema
  {
    "type" => "object",
    "properties" => {
      "path" => {
        "type" => "string",
        "description" => "Directory path relative to the working directory (default: working directory)"
      },
      "recursive" => {
        "type" => "boolean",
        "description" => "List entries recursively (default: false)"
      }
    },
    "required" => []
  }
end

#nameObject



9
10
11
# File 'lib/aiko/tools/list_files.rb', line 9

def name
  "list_files"
end