#!/usr/bin/env ruby require 'sord' require 'commander/import' require 'bundler' program :name, 'sord' program :version, Sord::VERSION program :description, 'Generate Sorbet RBIs from YARD documentation' default_command :gen command :gen do |c| c.syntax = 'sord gen [options]' c.description = 'Generates an RBI file from this directory\'s YARD docs' c.option '--[no-]sord-comments', 'Controls informational/warning comments in the RBI file' c.option '--[no-]regenerate', 'Controls whether YARD is executed before Sord runs' c.option '--break-params INTEGER', Integer, 'Break params onto their own lines if there are this many' c.option '--replace-errors-with-untyped', 'Uses T.untyped rather than SORD_ERROR_ constants' c.option '--replace-unresolved-with-untyped', 'Uses T.untyped when Sord is unable to resolve a constant' c.option '--exclude-messages STRING', String, 'Blacklists a comma-separated string of log message types' c.option '--include-messages STRING', String, 'Whitelists a comma-separated string of log message types' c.option '--keep-original-comments', 'Retains original YARD comments rather than converting them to Markdown' c.option '--skip-constants', 'Excludes constants from generated RBI' c.action do |args, options| options.default( sord_comments: true, regenerate: true, break_params: 4, replace_errors_with_untyped: false, replace_unresolved_with_untyped: false, exclude_messages: nil, include_messages: nil, keep_original_comments: false, skip_constants: false ) if args.length != 1 Sord::Logging.error('Must specify filename') exit 1 end plugin_options = options.__hash__ plugin_options[:exclude_options] = plugin_options[:exclude_options]&.split(',') plugin_options[:include_options] = plugin_options[:include_options]&.split(',') plugin = Sord::ParlourPlugin.new(plugin_options) plugin.parlour = Parlour::RbiGenerator.new(break_params: plugin_options[:break_params]) plugin.generate(plugin.parlour.root) File.write(args.first, plugin.parlour.rbi) end end