Class: MixinBot::UtilsCLI
- Inherits:
-
Thor
- Object
- Thor
- MixinBot::UtilsCLI
- Includes:
- CLIHelpers, CLIOutput
- Defined in:
- lib/mixin_bot/cli/utils.rb
Constant Summary
Constants included from CLIHelpers
CLIHelpers::API_EXCLUDED_METHODS, CLIHelpers::INTERACTIVE_API_METHODS
Constants included from CLIOutput
Instance Method Summary collapse
Methods included from CLIHelpers
api_callable_methods, api_method_callable?, api_method_owner, grouped_api_methods, utils_callable_methods
Methods included from CLIOutput
#abort_with_error, #cli_options, #current_command_name, #emit_info, #emit_list, #emit_success, #log, #output_format, #paginate_items, #print_result, #select_fields, #structured_output?, #with_command_name
Instance Method Details
#call(method_name, *positional) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/mixin_bot/cli/utils.rb', line 10 def call(method_name, *positional) with_command_name('utils call') do kwargs = parse_utils_json_data([:data]) result = invoke_utils_method(method_name, kwargs:, positional:) emit_success(result, command: 'utils call') end end |
#list(filter = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mixin_bot/cli/utils.rb', line 22 def list(filter = nil) with_command_name('utils list') do methods = CLIHelpers.utils_callable_methods if filter.present? needle = filter.downcase methods = methods.select { |m| m.to_s.downcase.include?(needle) } end items = methods.map { |name| { 'name' => name.to_s } } page, total, limit, offset = paginate_items(items, limit: [:limit], offset: [:offset]) page = select_fields(page, [:fields]) if structured_output? emit_list(items: page, total:, limit:, offset:, command: 'utils list') else page.each { |item| puts item['name'] } emit_info("Showing #{page.size} of #{total} (limit=#{limit}, offset=#{offset})") if total > limit || offset.positive? end end end |