class RBS::CLI
def run_ancestors(args, options)
def run_ancestors(args, options) # @type var kind: :instance | :singleton kind = :instance OptionParser.new do |opts| opts.banner = <<EOU e: rbs ancestors [options...] [type_name] ancestors of the given class or module. ples: rbs ancestors --instance String rbs ancestors --singleton Array ons: opts.on("--instance", "Ancestors of instance of the given type_name (default)") { kind = :instance } opts.on("--singleton", "Ancestors of singleton of the given type_name") { kind = :singleton } end.order!(args) loader = options.loader() env = Environment.from_loader(loader).resolve_type_names builder = DefinitionBuilder::AncestorBuilder.new(env: env) type_name = TypeName(args[0]).absolute! if env.class_decls.key?(type_name) ancestors = case kind when :instance builder.instance_ancestors(type_name) when :singleton builder.singleton_ancestors(type_name) else raise end ancestors.ancestors.each do |ancestor| case ancestor when Definition::Ancestor::Singleton stdout.puts "singleton(#{ancestor.name})" when Definition::Ancestor::Instance if ancestor.args.empty? stdout.puts ancestor.name.to_s else stdout.puts "#{ancestor.name}[#{ancestor.args.join(", ")}]" end end end else stdout.puts "Cannot find class: #{type_name}" end end