Class: CmdLineParser

Inherits:
Object
  • Object
show all
Defined in:
lib/giblish/cmdline.rb

Overview

Parse the cmd line arguments This implementation is heavily inspired by the following stack overflow answer: stackoverflow.com/questions/26434923/parse-command-line-arguments-in-a-ruby-script

Constant Summary collapse

USAGE =
<<~ENDUSAGE
  Usage:
    giblish [options] source_dir_top dest_dir_top
ENDUSAGE
HELP =
<<ENDHELP
 Options:
  -h --help                  show this help text
  -v --version               show version nr and exit
  -f --format <format>       the output format, currently html or pdf are supported
                             *html* is used if -f is not supplied
  -n --no-build-ref          suppress generation of a reference document at the destination
                             tree root.
  --index-basename           set the name of the generated index file (default 'index').
  -r --resource-dir <dir>    specify a directory where fonts, themes, css and other
                             central stuff needed for document generation are located.
                             The resources are expected to be located in a subfolder
                             whose name matches the resource type (font, theme
                             or css). If no resource dir is specified, the asciidoctor
                             defaults are used.
  -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)
  -i --include <regexp>      include only files with a path that matches the supplied
                             regexp (defaults to '.*\.(?i)adoc$' 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).
  -j --exclude <regexp>      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).
  -w --web-path <path>       Specifies the URL path to where the generated html documents
                             will be deployed (only needed when serving the html docs via
                             a web server).
                             E.g.
                             If the docs are deployed to 'www.example.com/site_1/blah',
                             this flag shall be set to '/site_1/blah'. This switch is only
                             used when generating html. giblish use this to link the deployed
                             html docs with the correct stylesheet.
  -g --git-branches <regExp> 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.
  -t --git-tags <regExp>     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.
  -c --local-only            do not try to fetch git info from any remotes of
                             the repo before generating documents.
  -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.
  -d --resolve-docid         use two passes, the first to collect :docid:
                             attributes in the doc headers, the second to
                             generate the documents and use the collected
                             doc ids to resolve relative paths between the
                             generated documents
  -m --make-searchable       (only supported for html generation)
                             take steps to make it possible to
                             search the published content via a cgi-script. 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 code that displays a search field in the
                                  index page that will try to call the cgi-script
                                  'giblish-search' when the user inputs some text.
                             To actually provide search functionality for a user, you
                             need to provide the cgi-script and configure your web-server
                             to invoke it when needed. NOTE: The generated search box cgi
                             is currently hard-coded to look for the cgi script at the URL:
                             http://<your-web-domain>/cgi-bin/giblish-search.cgi
                             E.g.
                             http://example.com/cgi-bin/giblish-search.cgi
                             An implementation of the giblish-search cgi-script is found
                             within the lib folder of this gem, you can copy that to your
                             cgi-bin dir in your webserver and rename it from .rb to .cgi
  -mp, --search-assets-deploy <path> the absolute path to the 'search_assets' folder where the search
                             script can find the data needed for implementing the text search
                             (default is <dst_dir_top>).
                             Set this to the file system path where the generated html
                             docs will be deployed (if different from dst_dir_top):
                             E.g.
                             If the generated html docs will be deployed to the folder
                             '/var/www/mysite/blah/mydocs,'
                             this is what you shall set the path to.
  --log-level                set the log level explicitly. Must be one of
                             debug, info (default), warn, error or fatal.
ENDHELP

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmdline_args) ⇒ CmdLineParser

Returns a new instance of CmdLineParser.


117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/giblish/cmdline.rb', line 117

def initialize(cmdline_args)
  parse_cmdline cmdline_args

  # handle help and version requests
  if @args[:help]
    puts USAGE
    puts ""
    puts HELP
    exit 0
  end
  if @args[:version]
    puts "Giblish v#{Giblish::VERSION}"
    exit 0
  end

  # act on the parsed cmd line args
  set_log_level
  sanity_check_input
  set_gitrepo_root
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.


9
10
11
# File 'lib/giblish/cmdline.rb', line 9

def args
  @args
end

Instance Method Details

#usageObject


138
139
140
# File 'lib/giblish/cmdline.rb', line 138

def usage
  USAGE
end