Module: Prmd::CLI
- Defined in:
- lib/prmd/cli.rb,
lib/prmd/cli/doc.rb,
lib/prmd/cli/base.rb,
lib/prmd/cli/render.rb,
lib/prmd/cli/verify.rb,
lib/prmd/cli/combine.rb,
lib/prmd/cli/generate.rb
Overview
Main CLI module
Defined Under Namespace
Modules: Base, Combine, Doc, Generate, Render, Verify
Class Method Summary collapse
-
.commands ⇒ Array
List of all available commands.
-
.make_command_parsers(props = {}) ⇒ Hash<Symbol, OptionParser>
All dem parsers.
-
.make_parser(options, props = {}) ⇒ Object
Creates the CLI main parser.
-
.parse_options(argv, opts = {}) ⇒ Hash<Symbol, Object>
Parse top level CLI options from argv.
-
.run(uargv, opts = {}) ⇒ void
Execute the Prmd CLI, or its subcommands.
Class Method Details
.commands ⇒ Array
List of all available commands
27 28 29 |
# File 'lib/prmd/cli.rb', line 27 def self.commands @commands ||= make_command_parsers.keys end |
.make_command_parsers(props = {}) ⇒ Hash<Symbol, OptionParser>
Returns all dem parsers.
14 15 16 17 18 19 20 21 22 |
# File 'lib/prmd/cli.rb', line 14 def self.make_command_parsers(props = {}) { combine: CLI::Combine.make_parser(props), doc: CLI::Doc.make_parser(props), init: CLI::Generate.make_parser(props), render: CLI::Render.make_parser(props), verify: CLI::Verify.make_parser(props) } end |
.make_parser(options, props = {}) ⇒ Object
Creates the CLI main parser
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/prmd/cli.rb', line 35 def self.make_parser(, props = {}) binname = props.fetch(:bin, 'prmd') # This is only used to attain the help commands commands = make_command_parsers(props) help_text = commands.values.map do |command| " #{command.}" end.join("\n") global = OptionParser.new do |opts| opts. = "Usage: #{binname} [options] [command [options]]" opts.separator "\nAvailable options:" opts.on('--version', 'Return version') do puts "prmd #{Prmd::VERSION}" exit(0) end opts.on('--noop', 'Commands will not execute') do |v| [:noop] = v end opts.separator "\nAvailable commands:" opts.separator help_text end global end |
.parse_options(argv, opts = {}) ⇒ Hash<Symbol, Object>
Parse top level CLI options from argv
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/prmd/cli.rb', line 66 def self.(argv, opts = {}) = {} parser = make_parser(, opts) abort parser if argv.empty? com_argv = parser.order(argv) abort parser if com_argv.empty? command = com_argv.shift.to_sym abort parser unless commands.include?(command) [:argv] = com_argv [:command] = command end |
.run(uargv, opts = {}) ⇒ void
This method returns an undefined value.
Execute the Prmd CLI, or its subcommands
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/prmd/cli.rb', line 84 def self.run(uargv, opts = {}) = (uargv, opts) argv = .delete(:argv) command = .delete(:command) case command when :combine CLI::Combine.run(argv, ) when :doc CLI::Doc.run(argv, ) when :init CLI::Generate.run(argv, ) when :render CLI::Render.run(argv, ) when :verify CLI::Verify.run(argv, ) end end |