lib/arli/cli/parser.rb in arli-0.8.3 vs lib/arli/cli/parser.rb in arli-0.9.0

- old
+ new

@@ -67,19 +67,36 @@ end def option_search on('-d', '--database URL', 'a JSON(.gz) file path or a URL of the library database.', - 'Defaults to the Arduino-maintained database.') do |v| + 'Defaults to the Arduino-maintained database.' + "\n\n") do |v| config.database.path = v end on('-m', '--max NUMBER', - 'if provided, limits the result set to this number', - 'Set to 0 to disable. Default is 100.') do |v| + 'if provided, limits the result set using the ', + 'total number of the unique library name matches.', + 'Default is 0, which means no limit.' + "\n\n") do |v| config.search.results.limit = v.to_i if v end + + formats = Arli::Library::MultiVersion.format_methods + + on('-f', '--format FMT', + "Optional format of the search results.", + "The default is #{'short'.bold.yellow}. Available ", + "formats: #{formats.join(', ').bold.yellow}\n\n") do |v| + if formats.include?(v.downcase.to_sym) + config.search.results.output_format = v.downcase.to_sym + else + raise ::OptionParser::InvalidOption, + "#{v.yellow} is not a supported search result format" + end + end + + option_search_attributes end def option_if_exists on('-e', '--if-exists ACTION', 'If a library folder already exists, by default', @@ -113,10 +130,21 @@ print_version_copyright end end end + def option_search_attributes + on('-A', '--print-attrs', 'prints full list of available library', + 'attributes that can be used in search strings.', ' ') do + + ::Arli.config.help = true + output '' + header('Arduino Library Attributes:') + output " • " + Arduino::Library::Types::LIBRARY_PROPERTIES.keys.join("\n • ") + "\n\n" + end + end + def header(string) output "#{string.bold.magenta}:" output end @@ -172,23 +200,20 @@ def common_help_options on('-C', '--no-color', 'Disable any color output.') do |*| Colored2.disable! # if $stdout.tty? + config.no_color = true end on('-D', '--debug', 'Print debugging info.') do |v| config.debug = true end on('-t', '--trace', 'Print exception stack traces.') do |v| config.trace = v end -# on('-n', '--dry-run', -# 'Only print actions, but do not do them.') do |v| -# config.trace = v -# end on('-v', '--verbose', 'Print more information.') do |v| config.verbose = true end on('-q', '--quiet', @@ -207,19 +232,21 @@ ' © 2017 Konstantin Gredeskoul, MIT License.'.dark unless Arli.config.quiet end def output_command_description(command_name) command_hash = factory.command_parsers[command_name] - indent = ' ' + indent = ' ' if command_hash if command_hash.description header 'Description' if command_hash.sentence output indent + command_hash.sentence.bold output '' end - output indent + Array(command_hash[:description]).map(&:dark).join('').gsub(/\n/, "\n#{indent}") + + text = Array(command_hash[:description]).flatten.join(' ') + output text.reformat_wrapped(width = 70, indent_with = 8) end end command_hash end