Sha256: 239f4b0b2b21a9e73a3a4aedf25bf1e3da9146ef275488d03c28942568a82ffa

Contents?: true

Size: 1.69 KB

Versions: 11

Compression:

Stored size: 1.69 KB

Contents

class Ufo::CLI
  module Help
    extend ActiveSupport::Concern

    class_methods do
      def main_commands
        %w[
          destroy
          exec
          logs
          ps
          ship
        ]
      end

      def help(shell, subcommand)
        list = printable_commands(true, subcommand)
        list.sort! { |a, b| a[0] <=> b[0] }
        filter = Proc.new do |command, desc|
          command = command.sub(/ --.*/,'')
          puts "command #{command.inspect}".color(:yellow)
          detected = main_commands.detect do |c|
            expr = "^ufo #{c}$"
            puts "expr #{expr}"
            command =~ Regexp.new(expr)
          end
          puts "detected #{detected.inspect}"
          detected
        end
        main = list.select(&filter)
        other = list.reject(&filter)

        shell.say <<~EOL
          Usage: ufo COMMAND [args]
          The available commands are listed below.
          The primary workflow commands are given first, followed by
          less common or more advanced commands.
        EOL
        shell.say "\nMain Commands:\n\n"
        shell.print_table(main, :indent => 2, :truncate => true)
        shell.say "\nOther Commands:\n\n"
        shell.print_table(other, :indent => 2, :truncate => true)
        shell.say <<~EOL

          For more help on each command, you can use the -h option. Example:

              ufo ship -h

          CLI Reference also available at: https://ufoships.com/reference/
        EOL
      end
    end

    def text(namespaced_command)
      path = namespaced_command.to_s.gsub(':','/')
      path = File.expand_path("../help/#{path}.md", __FILE__)
      IO.read(path) if File.exist?(path)
    end

    extend self
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
ufo-6.1.0 lib/ufo/cli/help.rb
ufo-6.0.9 lib/ufo/cli/help.rb
ufo-6.0.8 lib/ufo/cli/help.rb
ufo-6.0.7 lib/ufo/cli/help.rb
ufo-6.0.6 lib/ufo/cli/help.rb
ufo-6.0.5 lib/ufo/cli/help.rb
ufo-6.0.4 lib/ufo/cli/help.rb
ufo-6.0.3 lib/ufo/cli/help.rb
ufo-6.0.2 lib/ufo/cli/help.rb
ufo-6.0.1 lib/ufo/cli/help.rb
ufo-6.0.0 lib/ufo/cli/help.rb