Sha256: 14ecb87baa2394f955f1e42ac3ff9176173a496b79ec41c81363ce47eb784d23
Contents?: true
Size: 1.87 KB
Versions: 2
Compression:
Stored size: 1.87 KB
Contents
# encoding: utf-8 module GithubCLI # Responsible for manipulating commands usage string. class Command class Usage DEFAULT_INDENT = 12 # Returns command attr_reader :command # Returns command flags attr_reader :flags # Initializes an usage instance # def initialize(command, flags, options={}) @command = Command.command_to_show(command) @flags = flags end # Options # indent - Indent the line with by indent value. Assumes that the first # the first line is already filled in with other padding. # length - Line length, otherwise the default terminal width is assumed. def format_usage(options={}) synopsis = "#{flags}#{command} <subcommand> [<args>]" indent = options[:indent] || DEFAULT_INDENT padding = sprintf("%#{indent}s",'') length = options[:length] || Terminal.default_width wrap synopsis, length, indent, padding end def tokenize_text(text) text.split(/\s+/).map(&:chomp).reject(&:empty?) end # Wraps text at the given line length using given indent value. # def wrap(text, length, indent=0, padding=0) if text.length > length - indent paragraphs = [] line = '' tokenize_text(text).each do |fragment| if line.length < length - indent line << fragment + ' ' else paragraphs << line line = padding + fragment + ' ' end end paragraphs << line text = paragraphs.join("\n") end text end # Returns a concise string representation of Usage instance # def inspect "#<#{self.class.inspect} @command=#{command.inspect} @flags=#{flags.inspect}" end end # Usage end # Command end # GithubCLI
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
github_cli-0.6.2 | lib/github_cli/command/usage.rb |
github_cli-0.6.1 | lib/github_cli/command/usage.rb |