lib/jsduck/options.rb in jsduck-3.0.1 vs lib/jsduck/options.rb in jsduck-3.1.0

- old
+ new

@@ -1,7 +1,8 @@ require 'optparse' require 'jsduck/meta_tag_loader' +require 'jsduck/logger' module JsDuck # Keeps command line options class Options @@ -9,12 +10,10 @@ attr_accessor :output_dir attr_accessor :ignore_global attr_accessor :external_classes attr_accessor :meta_tags - attr_accessor :warnings - attr_accessor :verbose # Customizing output attr_accessor :title attr_accessor :header attr_accessor :footer @@ -22,10 +21,11 @@ attr_accessor :body_html attr_accessor :welcome attr_accessor :guides attr_accessor :videos attr_accessor :examples + attr_accessor :stats attr_accessor :categories_path attr_accessor :pretty_json attr_accessor :images attr_accessor :link_tpl attr_accessor :img_tpl @@ -71,13 +71,11 @@ "Mixed", ] @meta_tags = [] @meta_tag_paths = [] - @warnings = true - @verbose = false - @version = "3.0.1" + @version = "3.1.0" # Customizing output @title = "Sencha Docs - Ext JS" @header = "<strong>Sencha Docs</strong> Ext JS" @footer = "Generated with <a href='https://github.com/senchalabs/jsduck'>JSDuck</a> #{@version}." @@ -85,10 +83,11 @@ @body_html = "" @welcome = nil @guides = nil @videos = nil @examples = nil + @stats = false @categories_path = nil @pretty_json = false @images = [] @link_tpl = '<a href="#!/api/%c%-%m" rel="%c%-%m" class="docClass">%a</a>' # Note that we wrap image template inside <p> because {@img} often @@ -128,12 +127,13 @@ return OptionParser.new do | opts | opts.banner = "Usage: jsduck [options] files/dirs...\n\n" opts.on('-o', '--output=PATH', "Directory to output all this amazing documentation.", - "This option MUST be specified (unless --stdout).", " ") do |path| - @output_dir = canonical(path) + "This option MUST be specified (unless --stdout).", + "Use dash '-' to write docs to STDOUT (only export).", " ") do |path| + @output_dir = path == "-" ? :stdout : canonical(path) end opts.on('--ignore-global', "Turns off the creation of global class.", " ") do @ignore_global = true end @@ -150,20 +150,21 @@ read_filenames(@root_dir + "/js-classes") end opts.on('--meta-tags=PATH', "Path to Ruby file or directory with custom", - "meta-tag implementations. Experimantal!", " ") do |path| - @meta_tag_paths << path + "meta-tag implementations.", " ") do |path| + @meta_tag_paths << canonical(path) end - opts.on('--no-warnings', "Turns off warnings.", " ") do - @warnings = false + opts.on('--no-warnings', + "Turns off all warnings. Same as --warnings=-all", " ") do + Logger.instance.set_warning(:all, false) end opts.on('-v', '--verbose', "This will fill up your console.", " ") do - @verbose = true + Logger.instance.verbose = true end opts.separator "Customizing output:" opts.separator "" @@ -209,10 +210,15 @@ opts.on('--examples=PATH', "Path JSON file describing the examples.", " ") do |path| @examples = canonical(path) end + opts.on('--stats', + "Creates page with all kinds of statistics. Experimental!", " ") do + @stats = true + end + opts.on('--categories=PATH', "Path to JSON file which defines categories for classes.", " ") do |path| @categories_path = canonical(path) end @@ -247,18 +253,17 @@ "%a - alt text for image", "Default is: '<p><img src=\"doc-resources/%u\" alt=\"%a\"></p>'", " ") do |tpl| @img_tpl = tpl end - opts.on('--json', "Produces JSON export instead of HTML documentation.", " ") do - @export = :json + opts.on('--export=TYPE', + "Exports docs in JSON. TYPE is one of:", + "* full - full class docs.", + "* api - only class- and member names.", " ") do |format| + @export = format.to_sym end - opts.on('--stdout', "Writes JSON export to STDOUT instead of writing to the filesystem", " ") do - @export = :stdout - end - opts.on('--seo', "Creates index.php that handles search engine traffic.", " ") do @seo = true end opts.on('--eg-iframe=PATH', @@ -268,10 +273,25 @@ end opts.separator "Debugging:" opts.separator "" + opts.on('--warnings=+A,-B,+C', Array, + "Turns warnings selectively on/off.", + "+foo turns on a warning, -foo turns it off.", + "Possible warning types are:", + " ", + *Logger.instance.doc_warnings) do |warnings| + warnings.each do |op| + if op =~ /^([-+]?)(.*)$/ + enable = !($1 == "-") + name = $2.to_sym + Logger.instance.set_warning(name, enable) + end + end + end + # For debugging it's often useful to set --processes=0 to get deterministic results. opts.on('-p', '--processes=COUNT', "The number of parallel processes to use.", OS::windows? ? "Defaults to off in Windows." : "Defaults to the number of processors/cores.", "Set to 0 to disable parallel processing completely.", " ") do |count| @@ -367,11 +387,11 @@ Dir[fname+"/**/*.{js,css,scss}"].each {|f| @input_files << f } else @input_files << fname end else - $stderr.puts "Warning: File #{fname} not found" + Logger.instance.warn(nil, "File #{fname} not found") end end # Converts relative path to full path # @@ -385,10 +405,16 @@ # Runs checks on the options def validate if @input_files.length == 0 && !@welcome && !@guides && !@videos && !@examples puts "You should specify some input files, otherwise there's nothing I can do :(" exit(1) - elsif @export != :stdout + elsif @output_dir == :stdout && !@export + puts "Output to STDOUT only works when using --export option." + exit(1) + elsif ![nil, :full, :api].include?(@export) + puts "Unknown export format: #{@export}" + exit(1) + elsif @output_dir != :stdout if !@output_dir puts "You should also specify an output directory, where I could write all this amazing documentation." exit(1) elsif File.exists?(@output_dir) && !File.directory?(@output_dir) puts "Oh noes! The output directory is not really a directory at all :("