Sha256: b0a22a17c22246953ca9805e6777045e19a5080a216cda891ddb5ddc5913fda0
Contents?: true
Size: 1.48 KB
Versions: 16
Compression:
Stored size: 1.48 KB
Contents
# encoding: utf-8 module GithubCLI # Provides command completion/suggestion for mistyped command or subcommand. class Command class Completion include GithubCLI::Util # Command to be looked up. attr_accessor :command def initialize(command) @command = command end DEFAULT_INDENT = 8 # If there is more than one possible alternative, show all of them. # def find_command_possibilities max_length = 1 commands = Command.all.select do |cmd| prefix = Util.longest_common_prefix(command, cmd.namespace) if !prefix.empty? && (prefix.length >= max_length) max_length = prefix.length cmd end end commands.map(&:namespace).uniq.sort end # Options # indent - Indent suggested commands by specified value. # def format_command_possibilities(options={}) possibilities = find_command_possibilities string = "" indent = options[:indent] || DEFAULT_INDENT if possibilities.size >= 1 string << "\n\nDid you mean this?\n" possibilities.each do |possibility| string << " " * indent + "#{possibility}\n" end end string end # Returns a concise string representation of Completion instance # def inspect "#<#{self.class.inspect} @command=#{command.inspect}" end end # Completion end # Command end # GithubCLI
Version data entries
16 entries across 16 versions & 1 rubygems