module Abt::Docs::Cli

Public Class Methods

commands() click to toggle source
# File lib/abt/docs/cli.rb, line 34
        def commands
          <<~TXT
            Printing commands

            Run commands with --help flag to see detailed usage and flags, e.g.:
               abt track harvest -h

            #{commands_per_provider}
          TXT
        end
examples() click to toggle source
# File lib/abt/docs/cli.rb, line 24
        def examples
          <<~TXT
            Printing examples

            #{formatted_examples(Docs.basic_examples)}

            #{formatted_examples(Docs.extended_examples)}
          TXT
        end
help() click to toggle source
# File lib/abt/docs/cli.rb, line 7
        def help
          <<~TXT
            Usage: #{usage_line}

            <command>   Name of command to execute, e.g. start, finalize etc.
            <ARI>       A URI-like resource identifier with a scheme and an optional path
                        in the format: <scheme>[:<path>]. E.g., harvest:11111111/22222222
            <options>   Optional flags for the command and ARI

            #{formatted_examples(Docs.basic_examples)}

            For detailed examples/commands try:
               abt examples
               abt commands
          TXT
        end

Private Class Methods

commands_per_provider() click to toggle source
# File lib/abt/docs/cli.rb, line 67
def commands_per_provider
  lines = []

  Docs.providers.each_with_index do |(scheme, commands_definition), index|
    lines << "" unless index.zero?
    lines << "#{inflector.humanize(scheme)}:"

    max_length = commands_definition.keys.map(&:length).max

    commands_definition.each do |(command, (_usage, description))|
      lines << "   #{command.ljust(max_length)}   #{description}"
    end
  end

  lines.join("\n")
end
formatted_examples(example_groups) click to toggle source
# File lib/abt/docs/cli.rb, line 51
def formatted_examples(example_groups)
  lines = []

  example_groups.each_with_index do |(title, examples), index|
    lines << "" unless index.zero?
    lines << title

    max_length = examples.keys.map(&:length).max
    examples.each do |(command, description)|
      lines << "   #{command.ljust(max_length)}   #{description}"
    end
  end

  lines.join("\n")
end
inflector() click to toggle source
# File lib/abt/docs/cli.rb, line 84
def inflector
  Dry::Inflector.new
end
usage_line() click to toggle source
# File lib/abt/docs/cli.rb, line 47
def usage_line
  "abt <command> [<ARI>] [<options> --] [<ARI>] ..."
end