giblish 0.8.2 → 1.0.0.rc2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/unit_tests.yml +30 -0
  3. data/.gitignore +7 -3
  4. data/.ruby-version +1 -1
  5. data/Changelog.adoc +61 -0
  6. data/README.adoc +267 -0
  7. data/docs/concepts/text_search.adoc +213 -0
  8. data/docs/concepts/text_search_im/cgi-search_request.puml +35 -0
  9. data/docs/concepts/text_search_im/cgi-search_request.svg +397 -0
  10. data/docs/concepts/text_search_im/search_request.puml +40 -0
  11. data/docs/concepts/text_search_im/search_request.svg +408 -0
  12. data/docs/howtos/trigger_generation.adoc +180 -0
  13. data/docs/{setup_server_assets → howtos/trigger_generation_im}/Render Documents.png +0 -0
  14. data/docs/{setup_server_assets → howtos/trigger_generation_im}/View Documents.png +0 -0
  15. data/docs/{setup_server_assets → howtos/trigger_generation_im}/deploy_with_hooks.graphml +0 -0
  16. data/docs/{setup_server_assets → howtos/trigger_generation_im}/deploy_with_hooks.svg +0 -0
  17. data/docs/{setup_server_assets → howtos/trigger_generation_im}/deploy_with_jenkins.graphml +0 -0
  18. data/docs/{setup_server_assets → howtos/trigger_generation_im}/deploy_with_jenkins.svg +0 -0
  19. data/docs/howtos/trigger_generation_im/docgen_github.puml +51 -0
  20. data/docs/{setup_server_assets → howtos/trigger_generation_im}/giblish_deployment.graphml +0 -0
  21. data/docs/howtos/trigger_generation_im/post-receive-example.sh +50 -0
  22. data/docs/reference/box_flow_spec.adoc +22 -0
  23. data/docs/reference/search_spec.adoc +185 -0
  24. data/giblish.gemspec +47 -29
  25. data/lib/giblish/adocsrc_providers.rb +23 -0
  26. data/lib/giblish/application.rb +214 -41
  27. data/lib/giblish/cmdline.rb +273 -259
  28. data/lib/giblish/config_utils.rb +41 -0
  29. data/lib/giblish/configurator.rb +163 -0
  30. data/lib/giblish/conversion_info.rb +120 -0
  31. data/lib/giblish/docattr_providers.rb +125 -0
  32. data/lib/giblish/docid/docid.rb +181 -0
  33. data/lib/giblish/github_trigger/webhook_manager.rb +64 -0
  34. data/lib/giblish/gitrepos/checkoutmanager.rb +124 -0
  35. data/lib/giblish/{gititf.rb → gitrepos/gititf.rb} +30 -4
  36. data/lib/giblish/gitrepos/gitsummary.erb +61 -0
  37. data/lib/giblish/gitrepos/gitsummaryprovider.rb +78 -0
  38. data/lib/giblish/gitrepos/history_pb.rb +41 -0
  39. data/lib/giblish/indexbuilders/d3treegraph.rb +88 -0
  40. data/lib/giblish/indexbuilders/depgraphbuilder.rb +109 -0
  41. data/lib/giblish/indexbuilders/dotdigraphadoc.rb +174 -0
  42. data/lib/giblish/indexbuilders/standard_index.erb +10 -0
  43. data/lib/giblish/indexbuilders/subtree_indices.rb +132 -0
  44. data/lib/giblish/indexbuilders/templates/circles.html.erb +111 -0
  45. data/lib/giblish/indexbuilders/templates/flame.html.erb +61 -0
  46. data/lib/giblish/indexbuilders/templates/tree.html.erb +366 -0
  47. data/lib/giblish/indexbuilders/templates/treemap.html.erb +127 -0
  48. data/lib/giblish/indexbuilders/verbatimtree.rb +94 -0
  49. data/lib/giblish/pathtree.rb +473 -74
  50. data/lib/giblish/resourcepaths.rb +150 -0
  51. data/lib/giblish/search/expand_adoc.rb +55 -0
  52. data/lib/giblish/search/headingindexer.rb +312 -0
  53. data/lib/giblish/search/request_manager.rb +110 -0
  54. data/lib/giblish/search/searchquery.rb +68 -0
  55. data/lib/giblish/search/textsearcher.rb +349 -0
  56. data/lib/giblish/subtreeinfobuilder.rb +77 -0
  57. data/lib/giblish/treeconverter.rb +272 -0
  58. data/lib/giblish/utils.rb +142 -294
  59. data/lib/giblish/version.rb +1 -1
  60. data/lib/giblish.rb +10 -7
  61. data/scripts/hooks/post-receive.example +66 -0
  62. data/{docgen/scripts/githook_examples → scripts/hooks}/post-update.example +0 -0
  63. data/{docgen → scripts}/resources/css/adoc-colony.css +0 -0
  64. data/scripts/resources/css/giblish-serif.css +419 -0
  65. data/scripts/resources/css/giblish.css +1979 -419
  66. data/{docgen → scripts}/resources/fonts/Ubuntu-B.ttf +0 -0
  67. data/{docgen → scripts}/resources/fonts/Ubuntu-BI.ttf +0 -0
  68. data/{docgen → scripts}/resources/fonts/Ubuntu-R.ttf +0 -0
  69. data/{docgen → scripts}/resources/fonts/Ubuntu-RI.ttf +0 -0
  70. data/{docgen → scripts}/resources/fonts/mplus1p-regular-fallback.ttf +0 -0
  71. data/{docgen → scripts}/resources/images/giblish_logo.png +0 -0
  72. data/{docgen → scripts}/resources/images/giblish_logo.svg +0 -0
  73. data/{docgen → scripts}/resources/themes/giblish.yml +0 -0
  74. data/scripts/wserv_development.rb +32 -0
  75. data/web_apps/cgi_search/gibsearch.rb +43 -0
  76. data/web_apps/gh_webhook_trigger/config.ru +2 -0
  77. data/web_apps/gh_webhook_trigger/gh_webhook_trigger.rb +73 -0
  78. data/web_apps/gh_webhook_trigger/public/dummy.txt +3 -0
  79. data/web_apps/sinatra_search/config.ru +2 -0
  80. data/web_apps/sinatra_search/public/dummy.txt +3 -0
  81. data/web_apps/sinatra_search/sinatra_search.rb +34 -0
  82. data/web_apps/sinatra_search/tmp/restart.txt +0 -0
  83. metadata +168 -73
  84. data/.rubocop.yml +0 -7
  85. data/.travis.yml +0 -3
  86. data/Changelog +0 -16
  87. data/Gemfile +0 -4
  88. data/README.adoc +0 -1
  89. data/Rakefile +0 -41
  90. data/bin/console +0 -14
  91. data/bin/setup +0 -8
  92. data/data/testdocs/malformed/no_header.adoc +0 -5
  93. data/data/testdocs/toplevel.adoc +0 -19
  94. data/data/testdocs/wellformed/adorned_purpose.adoc +0 -17
  95. data/data/testdocs/wellformed/docidtest/docid_1.adoc +0 -24
  96. data/data/testdocs/wellformed/docidtest/docid_2.adoc +0 -8
  97. data/data/testdocs/wellformed/simple.adoc +0 -14
  98. data/data/testdocs/wellformed/source_highlighting/highlight_source.adoc +0 -38
  99. data/docgen/resources/css/giblish.css +0 -1979
  100. data/docgen/scripts/Jenkinsfile +0 -18
  101. data/docgen/scripts/gen_adoc_org.sh +0 -58
  102. data/docs/README.adoc +0 -387
  103. data/docs/setup_server.adoc +0 -202
  104. data/lib/giblish/buildgraph.rb +0 -216
  105. data/lib/giblish/buildindex.rb +0 -459
  106. data/lib/giblish/core.rb +0 -451
  107. data/lib/giblish/docconverter.rb +0 -308
  108. data/lib/giblish/docid.rb +0 -180
  109. data/lib/giblish/docinfo.rb +0 -75
  110. data/lib/giblish/indexheadings.rb +0 -251
  111. data/lib/giblish-search.cgi +0 -459
  112. data/scripts/hooks/post-receive +0 -57
  113. data/scripts/publish_html.sh +0 -99
@@ -1,284 +1,298 @@
1
- require_relative "utils"
2
- require_relative "version"
1
+ require "optparse"
2
+ require "logger"
3
3
 
4
- # Parse the cmd line arguments
5
- # This implementation is heavily inspired by the following
6
- # stack overflow answer:
7
- # http://stackoverflow.com/questions/26434923/parse-command-line-arguments-in-a-ruby-script
8
- class CmdLineParser
9
- attr_accessor :args
4
+ module Giblish
5
+ # parse the cmd line
6
+ class CmdLine
7
+ # Container class for all supported options that are
8
+ # accessible via the cmd line.
9
+ class Options
10
+ attr_accessor :format, :no_index, :index_basename, :graph_basename, :include_regex, :exclude_regex,
11
+ :copy_asset_folders, :resource_dir, :style_name, :server_css, :branch_regex, :tag_regex, :local_only, :doc_attributes,
12
+ :resolve_docid, :make_searchable, :search_action_path, :abort_on_error, :log_level, :srcdir, :dstdir, :web_path
10
13
 
11
- USAGE = <<~ENDUSAGE
12
- Usage:
13
- giblish [options] source_dir_top dest_dir_top
14
- ENDUSAGE
15
- HELP = <<ENDHELP
16
- Options:
17
- -h --help show this help text
18
- -v --version show version nr and exit
19
- -f --format <format> the output format, currently html or pdf are supported
20
- *html* is used if -f is not supplied
21
- -n --no-build-ref suppress generation of a reference document at the destination
22
- tree root.
23
- --index-basename set the name of the generated index file (default 'index').
24
- -r --resource-dir <dir> specify a directory where fonts, themes, css and other
25
- central stuff needed for document generation are located.
26
- The resources are expected to be located in a subfolder
27
- whose name matches the resource type (font, theme
28
- or css). If no resource dir is specified, the asciidoctor
29
- defaults are used.
30
- -s --style <name> The style information used when converting the documents
31
- using the -r option for specifying resource directories.
32
- For html this is a name of a css file, for pdf, this is
33
- the name of an yml file. You can specify only the
34
- basename of the file and giblish will use the suffix
35
- associated with the output format (i.e specify 'mystyle'
36
- and the mystyle.css and mystyle.yml will be used for html
37
- and pdf generation respectively)
38
- -i --include <regexp> include only files with a path that matches the supplied
39
- regexp (defaults to '.*\.(?i)adoc$' meaning it matches all
40
- files ending in .adoc case-insensitive). The matching is made
41
- on the full path (i.e. the regex '^.*my.*' matches the path
42
- /my/file.adoc).
43
- -j --exclude <regexp> exclude files with a path that matches the supplied
44
- regexp (no files are excluded by default). The matching is made
45
- on the full path (i.e. the regex '^.*my.*' matches the path
46
- /my/file.adoc).
47
- -w --web-path <path> Specifies the URL path to where the generated html documents
48
- will be deployed (only needed when serving the html docs via
49
- a web server).
50
- E.g.
51
- If the docs are deployed to 'www.example.com/site_1/blah',
52
- this flag shall be set to '/site_1/blah'. This switch is only
53
- used when generating html. giblish use this to link the deployed
54
- html docs with the correct stylesheet.
55
- -g --git-branches <regExp> if the source_dir_top is located within a git repo,
56
- generate docs for all _remote branches on origin_ that matches
57
- the given regular expression. Each git branch will
58
- be generated to a separate subdir under the destination
59
- root dir.
60
- NOTE: To do this, giblish will _explicitly check out the
61
- matching branches and merge them with the corresponding
62
- branch on origin_.
63
- NOTE 2: In bash, use double quotes around your regexp if
64
- you need to quote it. Single quotes are treated as part
65
- of the regexp itself.
66
- -t --git-tags <regExp> if the source_dir_top is located within a git repo,
67
- generate docs for all tags that matches the given
68
- regular expression. Each tag will be generated to
69
- a separate subdir under the destination root dir.
70
- -c --local-only do not try to fetch git info from any remotes of
71
- the repo before generating documents.
72
- -a --attribute <key>=<value> set a document or asciidoctor attribute.
73
- The contents of this flag is passed directly to the
74
- underlying asciidoctor tool, for details above the
75
- syntax and available attributes, see the documentation for
76
- asciidoctor. This option can be specified more than once.
77
- -d --resolve-docid use two passes, the first to collect :docid:
78
- attributes in the doc headers, the second to
79
- generate the documents and use the collected
80
- doc ids to resolve relative paths between the
81
- generated documents
82
- -m --make-searchable (only supported for html generation)
83
- take steps to make it possible to
84
- search the published content via a cgi-script. This
85
- flag will do the following:
86
- 1. index all headings in all source files and store
87
- the result in a JSON file
88
- 2. copy the JSON file and all source (adoc) files to
89
- a 'search_assets' folder in the top-level dir of
90
- the destination.
91
- 3. add html code that displays a search field in the
92
- index page that will try to call the cgi-script
93
- 'giblish-search' when the user inputs some text.
94
- To actually provide search functionality for a user, you
95
- need to provide the cgi-script and configure your web-server
96
- to invoke it when needed. NOTE: The generated search box cgi
97
- is currently hard-coded to look for the cgi script at the URL:
98
- http://<your-web-domain>/cgi-bin/giblish-search.cgi
99
- E.g.
100
- http://example.com/cgi-bin/giblish-search.cgi
101
- An implementation of the giblish-search cgi-script is found
102
- within the lib folder of this gem, you can copy that to your
103
- cgi-bin dir in your webserver and rename it from .rb to .cgi
104
- -mp, --search-assets-deploy <path> the absolute path to the 'search_assets' folder where the search
105
- script can find the data needed for implementing the text search
106
- (default is <dst_dir_top>).
107
- Set this to the file system path where the generated html
108
- docs will be deployed (if different from dst_dir_top):
109
- E.g.
110
- If the generated html docs will be deployed to the folder
111
- '/var/www/mysite/blah/mydocs,'
112
- this is what you shall set the path to.
113
- --log-level set the log level explicitly. Must be one of
114
- debug, info (default), warn, error or fatal.
115
- ENDHELP
14
+ OUTPUT_FORMATS = ["html", "pdf"]
116
15
 
117
- def initialize(cmdline_args)
118
- parse_cmdline cmdline_args
16
+ LOG_LEVELS = {
17
+ "debug" => Logger::DEBUG,
18
+ "info" => Logger::INFO,
19
+ "warn" => Logger::WARN,
20
+ "error" => Logger::ERROR,
21
+ "fatal" => Logger::FATAL
22
+ }
119
23
 
120
- # handle help and version requests
121
- if @args[:help]
122
- puts USAGE
123
- puts ""
124
- puts HELP
125
- exit 0
126
- end
127
- if @args[:version]
128
- puts "Giblish v#{Giblish::VERSION}"
129
- exit 0
130
- end
131
-
132
- # act on the parsed cmd line args
133
- set_log_level
134
- sanity_check_input
135
- set_gitrepo_root
136
- end
24
+ def initialize
25
+ @format = OUTPUT_FORMATS[0]
26
+ @publish_type = :local
27
+ @no_index = false
28
+ @index_basename = "index"
29
+ @graph_basename = "gibgraph"
30
+ @include_regex, @exclude_regex = /.*\.(?i)adoc$/, nil
31
+ @copy_asset_folders = nil
32
+ @resource_dir = nil
33
+ @style_name = nil
34
+ @server_css = nil
35
+ # TODO: remove this soon
36
+ @web_path = nil
37
+ @branch_regex, @tag_regex = nil, nil
38
+ @local_only = false
39
+ @doc_attributes = {}
40
+ @resolve_docid = false
41
+ @make_searchable = false
42
+ @search_action_path = nil
43
+ @abort_on_error = true
44
+ @log_level = "info"
45
+ end
137
46
 
138
- def usage
139
- USAGE
140
- end
47
+ def define_options(parser)
48
+ parser.banner = "Usage: #{parser.program_name} [options] srcdir dstdir"
49
+ parser.separator ""
50
+ parser.separator "Converts asciidoc files found under 'srcdir' and store the converted"
51
+ parser.separator "files under 'dstdir'"
52
+ parser.separator ""
53
+ parser.separator " Options:"
141
54
 
142
- private
55
+ parser.on("-f", "--format [FORMAT]", OUTPUT_FORMATS,
56
+ "The output format of the converted files",
57
+ "Supported formats are: #{OUTPUT_FORMATS}") do |fmt|
58
+ @format = fmt
59
+ end
60
+ parser.on("-n", "--no-build-ref ", "Suppress generation of indices and",
61
+ "dependency graphs.") do |n|
62
+ @no_index = true
63
+ end
64
+ parser.on("--index-basename ", "Set the basename for generated index files",
65
+ "(default #{@index_basename})") do |name|
66
+ @index_basename = name
67
+ end
68
+ parser.on("-r", "--resource-dir [DIR]",
69
+ "Specify a directory tree within which fonts, themes, css and other",
70
+ "central stuff needed for document generation are located.",
71
+ "If no resource dir is specified, the asciidoctor",
72
+ "defaults are used. (default: nil)") do |resource_dir|
73
+ r = Pathname.new(resource_dir)
74
+ @resource_dir = (r.absolute? ? r : (Pathname.new(Dir.pwd) / r)).cleanpath
75
+ end
76
+ parser.on("-s", "--style [NAME]",
77
+ "The style information used when converting the documents",
78
+ "using the -r option for specifying resource directories.",
79
+ "For html this is a name of a css file, for pdf, this is",
80
+ "the name of an yml file. You can specify only the",
81
+ "basename of the file and giblish will use the suffix",
82
+ "associated with the output format (i.e specify 'mystyle'",
83
+ "and the mystyle.css and mystyle.yml will be used for html",
84
+ "and pdf generation respectively)",
85
+ "(default: nil -> use default style") do |style_name|
86
+ @style_name = style_name.to_s
87
+ end
88
+ parser.on("-i", "--include [REGEX]",
89
+ "include only files with a path that matches the supplied",
90
+ "regexp (defaults to #{@include_regex} meaning it matches all",
91
+ "files ending in .adoc case-insensitive). The matching is made",
92
+ "on the full path (i.e. the regex '^.*my.*' matches the path",
93
+ "/my/file.adoc).") do |regex_str|
94
+ @include_regex = Regexp.new(regex_str)
95
+ end
96
+ parser.on("-j", "--exclude [REGEX]",
97
+ "exclude files with a path that matches the supplied",
98
+ "regexp (no files are excluded by default). The matching is made",
99
+ "on the full path (i.e. the regex '^.*my.*' matches the path",
100
+ "/my/file.adoc).") do |regex_str|
101
+ @exclude_regex = Regexp.new(regex_str)
102
+ end
103
+ parser.on("--copy-asset-folders [REGEX]",
104
+ "copy the content of all folders matching the given regex.",
105
+ "The folders will be copied to the corresponding location under 'dstdir'",
106
+ "Default is to not copy any directories at all.",
107
+ "The matching is made on the full path (i.e. the regex '_assets$' matches the path",
108
+ "'my/subdir/doc_assets').") do |regex_str|
109
+ @copy_asset_folders = Regexp.new(regex_str)
110
+ end
111
+ parser.on("-w", "--web-path [PATH]",
112
+ "DEPRECATED!! You should use the server-search-path and",
113
+ "server-css-path flags instead.") do |path|
114
+ Giblog.logger.error { "The '-w' flag is DEPRECATED, use the '--server-search-path' and '--server-css-path' flags instead." }
115
+ @web_path = true
116
+ end
117
+ parser.on("--server-css-path [PATH]",
118
+ "Sets a specific path to the stylesheet used by the generated",
119
+ "html documents. This flag can be used instead of the 's' and",
120
+ "'r' flags if a pre-existing stylesheet exists at a known",
121
+ "location that is accessible from the generated documents via",
122
+ "an 'href' element.",
123
+ "This flag is only used for html generation.") do |path|
124
+ @server_css = Pathname.new(path)
125
+ end
126
+ parser.on("-g", "--git-branches [REGEX]",
127
+ "if the source_dir_top is located within a git repo,",
128
+ "generate docs for all _remote branches on origin_ that matches",
129
+ "the given regular expression. Each git branch will",
130
+ "be generated to a separate subdir under the destination",
131
+ "root dir.",
132
+ "NOTE: To do this, giblish will _explicitly check out the",
133
+ "matching branches and merge them with the corresponding",
134
+ "branch on origin_.",
135
+ "NOTE 2: In bash, use double quotes around your regexp if",
136
+ "you need to quote it. Single quotes are treated as part",
137
+ "of the regexp itself.") do |regex_str|
138
+ @branch_regex = Regexp.new(regex_str)
139
+ end
140
+ parser.on("-t", "--git-tags [REGEX]",
141
+ "if the source_dir_top is located within a git repo,",
142
+ "generate docs for all tags that matches the given",
143
+ "regular expression. Each tag will be generated to",
144
+ "a separate subdir under the destination root dir.") do |regex_str|
145
+ @tag_regex = Regexp.new(regex_str)
146
+ end
147
+ parser.on("-c", "--local-only",
148
+ "do not try to fetch git info from any remotes of",
149
+ "the repo before generating documents.") do |local_only|
150
+ @local_only = true
151
+ end
152
+ parser.on("-a", "--attribute [KEY=VALUE]",
153
+ "set a document or asciidoctor attribute.",
154
+ "The contents of this flag is passed directly to the",
155
+ "underlying asciidoctor tool, for details above the",
156
+ "syntax and available attributes, see the documentation for",
157
+ "asciidoctor. This option can be specified more than once.") do |attr_str|
158
+ tokens = attr_str.split("=")
159
+ raise OptionParser::InvalidArgument, "Document attributs must be specified as 'key=value'!" unless tokens.count == 2
160
+ @doc_attributes[tokens[0]] = tokens[1]
161
+ end
162
+ parser.on("-d", "--resolve-docid",
163
+ "Collect document ids in the form of :docid:",
164
+ "attributes in the doc headers. Use these ids to",
165
+ "resolve cross-references of docid:s from one document",
166
+ "to another.") do |d|
167
+ @resolve_docid = d
168
+ end
169
+ parser.on("-m", "--make-searchable",
170
+ "(only supported for html generation)",
171
+ "take steps to make it possible to search the generated",
172
+ "docs via the web server through which they are published.",
173
+ "This flag will do the following:",
174
+ " 1. index all headings in all source files and store",
175
+ " the result in a JSON file",
176
+ " 2. copy the JSON file and all source (adoc) files to",
177
+ " a 'search_assets' folder in the top-level dir of",
178
+ " the destination.",
179
+ " 3. add html/javascript code that displays a search form",
180
+ " at the top of the generated documents. The search form",
181
+ " sends a html POST to the path specified with the ",
182
+ " 'server-search-path' flag when the user inputs some text.",
183
+ "To actually provide search functionality for readers, you",
184
+ "need to provide a server side script or application that can",
185
+ "respond to the html POST and return relevant info.",
186
+ "giblish contains most of the functionality for this and an",
187
+ "implementation of a cgi-script is bundled with this gem.") do |m|
188
+ @make_searchable = m
189
+ end
190
+ parser.on("--server-search-path URLPATH",
191
+ "the url path to which search requests are sent.",
192
+ "(default is #{@search_action_path}).",
193
+ "E.g.",
194
+ "If the search script resides under 'www.mysite.com/actions/gibsearch'",
195
+ "you would set this as '--server-search-path /actions/gibsearch'") do |p|
196
+ @search_action_path = Pathname.new(p)
197
+ end
198
+ parser.on("--continue", "Continue even if a conversion fails. Default is to stop") do
199
+ @abort_on_error = false
200
+ end
201
+ parser.on("-l", "--log-level LEVEL", LOG_LEVELS,
202
+ "set the log level explicitly. Must be one of",
203
+ LOG_LEVELS.keys.join(",").to_s, "(default 'info')") do |level|
204
+ @log_level = level
205
+ end
206
+ parser.on_tail("-h", "--help", "Show this message") do
207
+ puts parser
208
+ exit 0
209
+ end
210
+ parser.on_tail("-v", "--version", "Show version") do
211
+ puts "Giblish v#{Giblish::VERSION}"
212
+ exit 0
213
+ end
214
+ end
143
215
 
144
- def set_log_level
145
- log_level = @args[:logLevel] || "info"
146
- case log_level
147
- when "debug" then Giblog.logger.sev_threshold = Logger::DEBUG
148
- when "info" then Giblog.logger.sev_threshold = Logger::INFO
149
- when "warn" then Giblog.logger.sev_threshold = Logger::WARN
150
- when "error" then Giblog.logger.sev_threshold = Logger::ERROR
151
- when "fatal" then Giblog.logger.sev_threshold = Logger::FATAL
152
- else
153
- puts "Invalid log level specified. Run with -h to see supported levels"
154
- puts USAGE
155
- exit 1
216
+ # enable pattern matching of instances as if they were
217
+ # a hash
218
+ def deconstruct_keys(keys)
219
+ h = {}
220
+ instance_variables.each do |v|
221
+ value = instance_variable_get(v)
222
+ h[v[1..].to_sym] = value unless value.nil?
223
+ end
224
+ h
225
+ end
156
226
  end
157
- end
158
-
159
- def sanity_check_input
160
- ensure_required_args
161
- prevent_invalid_combos
162
- end
163
227
 
164
- def parse_cmdline(cmdline_args)
165
- # default values for cmd line switches
166
- @args = {
167
- help: false,
168
- version: false,
169
- force: true,
170
- format: "html",
171
- # note that the single quotes are important for the regexp
172
- includeRegexp: '.*\.(?i)adoc$',
173
- excludeRegexp: nil,
174
- flatten: false,
175
- suppressBuildRef: false,
176
- indexBaseName: "index",
177
- localRepoOnly: false,
178
- resolveDocid: false,
179
- makeSearchable: false,
180
- searchAssetsDeploy: nil,
181
- webPath: nil
182
- }
228
+ # converts the given cmd line args to an Options instance.
229
+ #
230
+ # Raises MissingArgument or InvalidArgument if the cmd line arg
231
+ # validation fails.
232
+ #
233
+ # === Returns
234
+ # the CmdLine::Options instance corresponding to the given cmd line args
235
+ def parse(args)
236
+ @cmd_opts = Options.new
237
+ @args = OptionParser.new do |parser|
238
+ @cmd_opts.define_options(parser)
239
+ parser.parse!(args)
183
240
 
184
- # set default log level
185
- Giblog.logger.sev_threshold = Logger::WARN
241
+ # take care of positional arguments
242
+ raise OptionParser::MissingArgument, "Both srcdir and dstdir must be provided!" unless args.count == 2
186
243
 
187
- # defines args without a corresponding flag, the order is important
188
- unflagged_args = %i[srcDirRoot dstDirRoot]
189
-
190
- # parse cmd line
191
- next_arg = unflagged_args.first
192
- cmdline_args.each do |arg|
193
- case arg
194
- when "-h", "--help" then @args[:help] = true
195
- when "-v", "--version" then @args[:version] = true
196
- when "-f", "--format " then next_arg = :format
197
- when "-r", "--resource-dir" then next_arg = :resourceDir
198
- when "-n", "--no-build-ref" then @args[:suppressBuildRef] = true
199
- when "--index-basename" then next_arg = :indexBaseName
200
- when "-i", "--include" then next_arg = :includeRegexp
201
- when "-j", "--exclude" then next_arg = :excludeRegexp
202
- when "-g", "--git-branches" then next_arg = :gitBranchRegexp
203
- when "-t", "--git-tags" then next_arg = :gitTagRegexp
204
- when "-c", "--local-only" then @args[:localRepoOnly] = true
205
- when "-a", "--attribute" then next_arg = :attributes
206
- when "-d", "--resolve-docid" then @args[:resolveDocid] = true
207
- when "-m", "--make-searchable" then @args[:makeSearchable] = true
208
- when "-mp", "--search-assets-deploy" then next_arg = :searchAssetsDeploy
209
- when "-s", "--style" then next_arg = :userStyle
210
- when "-w", "--web-path" then next_arg = :webPath
211
- when "--log-level" then next_arg = :logLevel
212
- else
213
- if next_arg
214
- if next_arg == :attributes
215
- # support multiple invocations of -a
216
- add_attribute arg
217
- else
218
- @args[next_arg] = arg
219
- end
220
- unflagged_args.delete(next_arg)
244
+ # we always work with absolute paths
245
+ @cmd_opts.srcdir, @cmd_opts.dstdir = [args[0], args[1]].collect do |arg|
246
+ d = Pathname.new(arg)
247
+ d = Pathname.new(Dir.pwd) / d unless d.absolute?
248
+ d.cleanpath
221
249
  end
222
- next_arg = unflagged_args.first
250
+
251
+ validate_options(@cmd_opts)
223
252
  end
253
+ @cmd_opts
224
254
  end
225
- end
226
255
 
227
- # adds the str (must be in key=value format) to the
228
- # user defined attributes
229
- def add_attribute(attrib_str)
230
- kv = attrib_str.split("=")
231
- if kv.length != 2
232
- puts "Invalid attribute format: #{attrib_str} Must be <key>=<value>"
233
- exit 1
234
- end
256
+ private
235
257
 
236
- @args[:attributes] ||= {}
237
- @args[:attributes][kv[0]] = kv[1]
238
- end
258
+ # Raise InvalidArgument if an unsupported cmd line combo is
259
+ # discovered
260
+ def validate_options(opts)
261
+ unless opts.branch_regex || opts.tag_regex
262
+ # If git branches/tags are given, the source path might exist in the branch/tag, thus only check this
263
+ # for non-git executions
264
+ raise OptionParser::InvalidArgument, "Could not find source path #{opts.srcdir}" unless opts.srcdir.exist?
265
+ end
239
266
 
240
- def prevent_invalid_combos
241
- # Prevent contradicting options
242
- if !@args[:resourceDir] && @args[:userStyle]
243
- puts "Error: The given style would not be used since no resource dir "\
244
- "was specified (-s specified without -r)"
245
- elsif @args[:makeSearchable] && @args[:format] != "html"
246
- puts "Error: The --make-searchable option is only supported for "\
247
- "html rendering."
248
- elsif @args[:searchAssetsDeploy] && !@args[:makeSearchable]
249
- puts "Error: The --search-assets-deploy (-mp) flag is only supported in "\
250
- "combination with the --make-searchable (-m) flag."
251
- else
252
- return
253
- end
267
+ if opts.web_path
268
+ raise OptionParser::InvalidArgument, "The '-w/--web-path' flag is DEPRECATED. Use the --server-css-path and --server--search-path flags instead."
269
+ end
254
270
 
255
- puts USAGE
256
- exit 1
257
- end
271
+ if opts.server_css && (opts.resource_dir || opts.style_name)
272
+ raise OptionParser::InvalidArgument, "The '-w' flag can not be used with either of the '-r' or '-s' flags"
273
+ end
258
274
 
259
- def ensure_required_args
260
- # Exit if the user does not supply the required arguments
261
- return unless !@args[:srcDirRoot] || !@args[:dstDirRoot]
275
+ if opts.server_css && opts.format != "html"
276
+ raise OptionParser::InvalidArgument, "The '-w' flag can only be used for the 'html' format flags"
277
+ end
262
278
 
263
- puts "Error: Too few arguments."
264
- puts USAGE
265
- exit 1
266
- end
279
+ if opts.resource_dir.nil? ^ opts.style_name.nil?
280
+ raise OptionParser::InvalidArgument, "Either both '-s' and '-r' flags must be given or none of them."
281
+ end
267
282
 
268
- def set_gitrepo_root
269
- # if user don't want no git repo, we're done
270
- return unless @args[:gitBranchRegexp] || @args[:gitTagRegexp]
283
+ if opts.resource_dir && !opts.resource_dir.exist?
284
+ raise OptionParser::InvalidArgument, "Could not find resource path #{opts.resource_dir}"
285
+ end
271
286
 
272
- # The user wants to parse a git repo, check that the srcDirRoot is within a
273
- # git repo if the user wants to generate git-branch specific docs
274
- @args[:gitRepoRoot] = Giblish::PathManager.find_gitrepo_root(
275
- @args[:srcDirRoot]
276
- )
277
- return unless @args[:gitRepoRoot].nil?
287
+ if opts.make_searchable && opts.format != "html"
288
+ raise OptionParser::InvalidArgument, "Error: The --make-searchable option "\
289
+ "is only supported for html rendering."
290
+ end
278
291
 
279
- # We should not get here if everything is koscher...
280
- puts "Error: Source dir not in a git working dir despite -g or -t option given!"
281
- puts USAGE
282
- exit 1
292
+ if opts.search_action_path && !opts.make_searchable
293
+ raise OptionParser::InvalidArgument, "Error: The --server-search-path "\
294
+ "flag is only supported in combination with the --make-searchable (-m) flag."
295
+ end
296
+ end
283
297
  end
284
298
  end
@@ -0,0 +1,41 @@
1
+ module Giblish
2
+ # delegates all method calls to the first supplied delegate that
3
+ # implements it.
4
+ class DataDelegator
5
+ attr_reader :delegates
6
+
7
+ def initialize(*delegate_arr)
8
+ @delegates = Array(delegate_arr)
9
+ end
10
+
11
+ def add(delegate)
12
+ @delegates << delegate
13
+ end
14
+
15
+ # define this to short-cut circular references
16
+ #
17
+ # TODO: This should probably be avoided by refactoring the SuccessfulConversion
18
+ # class which, as of this writing, is part of a circular ref to a PathTree which
19
+ # throws 'inspect' calls into an eternal loop instead of implementing a custom 'inspect'
20
+ # method.
21
+ def inspect
22
+ @delegates.map do |d|
23
+ "<#{d.class}:#{d.object_id}>"
24
+ end.join(",")
25
+ end
26
+
27
+ def method_missing(m, *args, &block)
28
+ del = @delegates&.find { |d| d.respond_to?(m) }
29
+
30
+ del.nil? ? super : del.send(m, *args, &block)
31
+ end
32
+
33
+ def respond_to_missing?(method_name, include_private = false)
34
+ ok = @delegates.find { |d|
35
+ d.respond_to?(method_name)
36
+ }
37
+
38
+ ok || super(method_name, include_private)
39
+ end
40
+ end
41
+ end