Class: Giblish::CmdLine::Options
- Inherits:
-
Object
- Object
- Giblish::CmdLine::Options
- Defined in:
- lib/giblish/cmdline.rb
Overview
Container class for all supported options that are accessible via the cmd line.
Constant Summary collapse
- OUTPUT_FORMATS =
["html", "pdf"]
- LOG_LEVELS =
{ "debug" => Logger::DEBUG, "info" => Logger::INFO, "warn" => Logger::WARN, "error" => Logger::ERROR, "fatal" => Logger::FATAL }
Instance Attribute Summary collapse
-
#abort_on_error ⇒ Object
Returns the value of attribute abort_on_error.
-
#branch_regex ⇒ Object
Returns the value of attribute branch_regex.
-
#copy_asset_folders ⇒ Object
Returns the value of attribute copy_asset_folders.
-
#doc_attributes ⇒ Object
Returns the value of attribute doc_attributes.
-
#dstdir ⇒ Object
Returns the value of attribute dstdir.
-
#exclude_regex ⇒ Object
Returns the value of attribute exclude_regex.
-
#format ⇒ Object
Returns the value of attribute format.
-
#graph_basename ⇒ Object
Returns the value of attribute graph_basename.
-
#include_regex ⇒ Object
Returns the value of attribute include_regex.
-
#index_basename ⇒ Object
Returns the value of attribute index_basename.
-
#local_only ⇒ Object
Returns the value of attribute local_only.
-
#log_level ⇒ Object
Returns the value of attribute log_level.
-
#make_searchable ⇒ Object
Returns the value of attribute make_searchable.
-
#no_index ⇒ Object
Returns the value of attribute no_index.
-
#resolve_docid ⇒ Object
Returns the value of attribute resolve_docid.
-
#resource_dir ⇒ Object
Returns the value of attribute resource_dir.
-
#search_action_path ⇒ Object
Returns the value of attribute search_action_path.
-
#server_css ⇒ Object
Returns the value of attribute server_css.
-
#srcdir ⇒ Object
Returns the value of attribute srcdir.
-
#style_name ⇒ Object
Returns the value of attribute style_name.
-
#tag_regex ⇒ Object
Returns the value of attribute tag_regex.
-
#web_path ⇒ Object
Returns the value of attribute web_path.
Instance Method Summary collapse
-
#deconstruct_keys(keys) ⇒ Object
enable pattern matching of instances as if they were a hash.
- #define_options(parser) ⇒ Object
-
#initialize ⇒ Options
constructor
A new instance of Options.
Constructor Details
#initialize ⇒ Options
Returns a new instance of Options.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/giblish/cmdline.rb', line 24 def initialize @format = OUTPUT_FORMATS[0] @publish_type = :local @no_index = false @index_basename = "index" @graph_basename = "gibgraph" @include_regex, @exclude_regex = /.*\.(?i)adoc$/, nil @copy_asset_folders = nil @resource_dir = nil @style_name = nil @server_css = nil # TODO: remove this soon @web_path = nil @branch_regex, @tag_regex = nil, nil @local_only = false @doc_attributes = {} @resolve_docid = false @make_searchable = false @search_action_path = nil @abort_on_error = true @log_level = "info" end |
Instance Attribute Details
#abort_on_error ⇒ Object
Returns the value of attribute abort_on_error.
10 11 12 |
# File 'lib/giblish/cmdline.rb', line 10 def abort_on_error @abort_on_error end |
#branch_regex ⇒ Object
Returns the value of attribute branch_regex.
10 11 12 |
# File 'lib/giblish/cmdline.rb', line 10 def branch_regex @branch_regex end |
#copy_asset_folders ⇒ Object
Returns the value of attribute copy_asset_folders.
10 11 12 |
# File 'lib/giblish/cmdline.rb', line 10 def copy_asset_folders @copy_asset_folders end |
#doc_attributes ⇒ Object
Returns the value of attribute doc_attributes.
10 11 12 |
# File 'lib/giblish/cmdline.rb', line 10 def doc_attributes @doc_attributes end |
#dstdir ⇒ Object
Returns the value of attribute dstdir.
10 11 12 |
# File 'lib/giblish/cmdline.rb', line 10 def dstdir @dstdir end |
#exclude_regex ⇒ Object
Returns the value of attribute exclude_regex.
10 11 12 |
# File 'lib/giblish/cmdline.rb', line 10 def exclude_regex @exclude_regex end |
#format ⇒ Object
Returns the value of attribute format.
10 11 12 |
# File 'lib/giblish/cmdline.rb', line 10 def format @format end |
#graph_basename ⇒ Object
Returns the value of attribute graph_basename.
10 11 12 |
# File 'lib/giblish/cmdline.rb', line 10 def graph_basename @graph_basename end |
#include_regex ⇒ Object
Returns the value of attribute include_regex.
10 11 12 |
# File 'lib/giblish/cmdline.rb', line 10 def include_regex @include_regex end |
#index_basename ⇒ Object
Returns the value of attribute index_basename.
10 11 12 |
# File 'lib/giblish/cmdline.rb', line 10 def index_basename @index_basename end |
#local_only ⇒ Object
Returns the value of attribute local_only.
10 11 12 |
# File 'lib/giblish/cmdline.rb', line 10 def local_only @local_only end |
#log_level ⇒ Object
Returns the value of attribute log_level.
10 11 12 |
# File 'lib/giblish/cmdline.rb', line 10 def log_level @log_level end |
#make_searchable ⇒ Object
Returns the value of attribute make_searchable.
10 11 12 |
# File 'lib/giblish/cmdline.rb', line 10 def make_searchable @make_searchable end |
#no_index ⇒ Object
Returns the value of attribute no_index.
10 11 12 |
# File 'lib/giblish/cmdline.rb', line 10 def no_index @no_index end |
#resolve_docid ⇒ Object
Returns the value of attribute resolve_docid.
10 11 12 |
# File 'lib/giblish/cmdline.rb', line 10 def resolve_docid @resolve_docid end |
#resource_dir ⇒ Object
Returns the value of attribute resource_dir.
10 11 12 |
# File 'lib/giblish/cmdline.rb', line 10 def resource_dir @resource_dir end |
#search_action_path ⇒ Object
Returns the value of attribute search_action_path.
10 11 12 |
# File 'lib/giblish/cmdline.rb', line 10 def search_action_path @search_action_path end |
#server_css ⇒ Object
Returns the value of attribute server_css.
10 11 12 |
# File 'lib/giblish/cmdline.rb', line 10 def server_css @server_css end |
#srcdir ⇒ Object
Returns the value of attribute srcdir.
10 11 12 |
# File 'lib/giblish/cmdline.rb', line 10 def srcdir @srcdir end |
#style_name ⇒ Object
Returns the value of attribute style_name.
10 11 12 |
# File 'lib/giblish/cmdline.rb', line 10 def style_name @style_name end |
#tag_regex ⇒ Object
Returns the value of attribute tag_regex.
10 11 12 |
# File 'lib/giblish/cmdline.rb', line 10 def tag_regex @tag_regex end |
#web_path ⇒ Object
Returns the value of attribute web_path.
10 11 12 |
# File 'lib/giblish/cmdline.rb', line 10 def web_path @web_path end |
Instance Method Details
#deconstruct_keys(keys) ⇒ Object
enable pattern matching of instances as if they were a hash
218 219 220 221 222 223 224 225 |
# File 'lib/giblish/cmdline.rb', line 218 def deconstruct_keys(keys) h = {} instance_variables.each do |v| value = instance_variable_get(v) h[v[1..].to_sym] = value unless value.nil? end h end |
#define_options(parser) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/giblish/cmdline.rb', line 47 def (parser) parser. = "Usage: #{parser.program_name} [options] srcdir dstdir" parser.separator "" parser.separator "Converts asciidoc files found under 'srcdir' and store the converted" parser.separator "files under 'dstdir'" parser.separator "" parser.separator " Options:" parser.on("-f", "--format [FORMAT]", OUTPUT_FORMATS, "The output format of the converted files", "Supported formats are: #{OUTPUT_FORMATS}") do |fmt| @format = fmt end parser.on("-n", "--no-build-ref ", "Suppress generation of indices and", "dependency graphs.") do |n| @no_index = true end parser.on("--index-basename ", "Set the basename for generated index files", "(default #{@index_basename})") do |name| @index_basename = name end parser.on("-r", "--resource-dir [DIR]", "Specify a directory tree within which fonts, themes, css and other", "central stuff needed for document generation are located.", "If no resource dir is specified, the asciidoctor", "defaults are used. (default: nil)") do |resource_dir| r = Pathname.new(resource_dir) @resource_dir = (r.absolute? ? r : (Pathname.new(Dir.pwd) / r)).cleanpath end parser.on("-s", "--style [NAME]", "The style information used when converting the documents", "using the -r option for specifying resource directories.", "For html this is a name of a css file, for pdf, this is", "the name of an yml file. You can specify only the", "basename of the file and giblish will use the suffix", "associated with the output format (i.e specify 'mystyle'", "and the mystyle.css and mystyle.yml will be used for html", "and pdf generation respectively)", "(default: nil -> use default style") do |style_name| @style_name = style_name.to_s end parser.on("-i", "--include [REGEX]", "include only files with a path that matches the supplied", "regexp (defaults to #{@include_regex} meaning it matches all", "files ending in .adoc case-insensitive). The matching is made", "on the full path (i.e. the regex '^.*my.*' matches the path", "/my/file.adoc).") do |regex_str| @include_regex = Regexp.new(regex_str) end parser.on("-j", "--exclude [REGEX]", "exclude files with a path that matches the supplied", "regexp (no files are excluded by default). The matching is made", "on the full path (i.e. the regex '^.*my.*' matches the path", "/my/file.adoc).") do |regex_str| @exclude_regex = Regexp.new(regex_str) end parser.on("--copy-asset-folders [REGEX]", "copy the content of all folders matching the given regex.", "The folders will be copied to the corresponding location under 'dstdir'", "Default is to not copy any directories at all.", "The matching is made on the full path (i.e. the regex '_assets$' matches the path", "'my/subdir/doc_assets').") do |regex_str| @copy_asset_folders = Regexp.new(regex_str) end parser.on("-w", "--web-path [PATH]", "DEPRECATED!! You should use the server-search-path and", "server-css-path flags instead.") do |path| Giblog.logger.error { "The '-w' flag is DEPRECATED, use the '--server-search-path' and '--server-css-path' flags instead." } @web_path = true end parser.on("--server-css-path [PATH]", "Sets a specific path to the stylesheet used by the generated", "html documents. This flag can be used instead of the 's' and", "'r' flags if a pre-existing stylesheet exists at a known", "location that is accessible from the generated documents via", "an 'href' element.", "This flag is only used for html generation.") do |path| @server_css = Pathname.new(path) end parser.on("-g", "--git-branches [REGEX]", "if the source_dir_top is located within a git repo,", "generate docs for all _remote branches on origin_ that matches", "the given regular expression. Each git branch will", "be generated to a separate subdir under the destination", "root dir.", "NOTE: To do this, giblish will _explicitly check out the", "matching branches and merge them with the corresponding", "branch on origin_.", "NOTE 2: In bash, use double quotes around your regexp if", "you need to quote it. Single quotes are treated as part", "of the regexp itself.") do |regex_str| @branch_regex = Regexp.new(regex_str) end parser.on("-t", "--git-tags [REGEX]", "if the source_dir_top is located within a git repo,", "generate docs for all tags that matches the given", "regular expression. Each tag will be generated to", "a separate subdir under the destination root dir.") do |regex_str| @tag_regex = Regexp.new(regex_str) end parser.on("-c", "--local-only", "do not try to fetch git info from any remotes of", "the repo before generating documents.") do |local_only| @local_only = true end parser.on("-a", "--attribute [KEY=VALUE]", "set a document or asciidoctor attribute.", "The contents of this flag is passed directly to the", "underlying asciidoctor tool, for details above the", "syntax and available attributes, see the documentation for", "asciidoctor. This option can be specified more than once.") do |attr_str| tokens = attr_str.split("=") raise OptionParser::InvalidArgument, "Document attributs must be specified as 'key=value'!" unless tokens.count == 2 @doc_attributes[tokens[0]] = tokens[1] end parser.on("-d", "--resolve-docid", "Collect document ids in the form of :docid:", "attributes in the doc headers. Use these ids to", "resolve cross-references of docid:s from one document", "to another.") do |d| @resolve_docid = d end parser.on("-m", "--make-searchable", "(only supported for html generation)", "take steps to make it possible to search the generated", "docs via the web server through which they are published.", "This flag will do the following:", " 1. index all headings in all source files and store", " the result in a JSON file", " 2. copy the JSON file and all source (adoc) files to", " a 'search_assets' folder in the top-level dir of", " the destination.", " 3. add html/javascript code that displays a search form", " at the top of the generated documents. The search form", " sends a html POST to the path specified with the ", " 'server-search-path' flag when the user inputs some text.", "To actually provide search functionality for readers, you", "need to provide a server side script or application that can", "respond to the html POST and return relevant info.", "giblish contains most of the functionality for this and an", "implementation of a cgi-script is bundled with this gem.") do |m| @make_searchable = m end parser.on("--server-search-path URLPATH", "the url path to which search requests are sent.", "(default is #{@search_action_path}).", "E.g.", "If the search script resides under 'www.mysite.com/actions/gibsearch'", "you would set this as '--server-search-path /actions/gibsearch'") do |p| @search_action_path = Pathname.new(p) end parser.on("--continue", "Continue even if a conversion fails. Default is to stop") do @abort_on_error = false end parser.on("-l", "--log-level LEVEL", LOG_LEVELS, "set the log level explicitly. Must be one of", LOG_LEVELS.keys.join(",").to_s, "(default 'info')") do |level| @log_level = level end parser.on_tail("-h", "--help", "Show this message") do puts parser exit 0 end parser.on_tail("-v", "--version", "Show version") do puts "Giblish v#{Giblish::VERSION}" exit 0 end end |