Module: Prmd::CLI
- Defined in:
- lib/prmd/cli.rb,
lib/prmd/cli/doc.rb,
lib/prmd/cli/base.rb,
lib/prmd/cli/stub.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, Stub, 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
29 30 31 |
# File 'lib/prmd/cli.rb', line 29 def self.commands @commands ||= make_command_parsers.keys end |
.make_command_parsers(props = {}) ⇒ Hash<Symbol, OptionParser>
Returns all dem parsers.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/prmd/cli.rb', line 15 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), stub: CLI::Stub.make_parser(props), verify: CLI::Verify.make_parser(props) } end |
.make_parser(options, props = {}) ⇒ Object
Creates the CLI main parser
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/prmd/cli.rb', line 37 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
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/prmd/cli.rb', line 68 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
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/prmd/cli.rb', line 86 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 :stub CLI::Stub.run(argv, ) when :verify CLI::Verify.run(argv, ) end end |