lib/arli/cli/parser.rb in arli-0.6.1 vs lib/arli/cli/parser.rb in arli-0.6.2

- old
+ new

@@ -18,41 +18,56 @@ def sep(text = nil) separator text || '' end + def option_install + option_library_name + option_lib_home + option_dependency_file + option_if_exists + end + def option_dependency_file on('-a', '--arli-path PATH', 'Folder where ' + 'Arlifile'.green + ' is located,', "Defaults to the current directory.\n\n") do |v| config.arlifile.path = v end end + def option_library_name + on('-n', '--name NAME', + 'If provided a library name is searched and, if found', + 'installed. In this mode Arlifile not used.' + "\n\n") do |v| + config.install.library_names << { name: v } + end + end + def option_lib_home on('-l', '--libraries PATH', - 'Local folder where libraries are installed', + 'Local folder where custom Arduino libraries are installed', "Defaults to #{Arli.default_library_path}\n\n") do |v| config.libraries.path = v end end def option_search on('-d', '--database FILE/URL', - 'a JSON file name, or a URL that contains the index', - 'Defaults to the Arduino-maintained list') do |v| + 'a JSON(.gz) file path or a URL of the library database.', + 'Defaults to the Arduino-maintained database.') do |v| config.database.path = v end on('-m', '--max NUMBER', 'if provided, limits the result set to this number', - 'Defaults to 100') do |v| + 'Set to 0 to disable. Default is 100.') do |v| config.search.results.limit = v.to_i if v end end - def option_abort_if_exists + def option_if_exists on('-e', '--if-exists ACTION', 'If a library folder already exists, by default', 'it will be overwritten or updated if possible.', 'Alternatively you can either ' + 'abort'.bold.blue + ' or ' + 'backup'.bold.blue ) do |v| @@ -81,17 +96,29 @@ end output_help output_command_help if commands - if command_hash && command_hash[:example] - output 'Example:' - output ' ' + command_hash[:example] + if command_hash && command_hash[:examples] + output_examples(command_hash[:examples]) + else + print_version_copyright end end end + def output_examples(examples) + output 'Examples:' + indent = ' ' + examples.each do |example| + output + output indent + '# ' + example[:desc] + output indent + example[:cmd].green + output '' + end + end + def option_help_with_subtext option_help end def output_help @@ -109,11 +136,10 @@ subtext << %Q/#{sprintf(' %-12s', command.to_s).green} — #{sprintf('%s', config[:description]).blue}\n/ end subtext << <<-EOS See #{Arli::Configuration::ARLI_COMMAND.blue + ' command '.green + '--help'.yellow} for more information on a specific command. - EOS subtext end def output(value = nil) @@ -140,14 +166,23 @@ end on('-v', '--verbose', 'Print more information.') do |v| config.verbose = true end + on('-q', '--quiet', + 'Print less information.') do |v| + config.quiet = true + end on('-V', '--version', 'Print current version and exit') do |v| - puts 'Version: ' + Arli::VERSION - exit + print_version_copyright + Arli.config.help = true end + end + + def print_version_copyright + output << Arli::Configuration::ARLI_COMMAND.bold.yellow + ' (' + Arli::VERSION.bold.green + ')' + + " © 2017 Konstantin Gredeskoul, MIT License." end end end end