diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6a833dd2..6c86923a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,3 +52,23 @@ jobs: bundler-cache: true - name: Run RuboCop run: bash script/fmt + + cli_help_info_visualization: + name: "CLI Help Info Visualization" + runs-on: "ubuntu-latest" + strategy: + fail-fast: false + matrix: + ruby_version: + - 2.7 + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 5 + - name: "Set up Ruby ${{ matrix.ruby_version }}" + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby_version }} + bundler-cache: true + - name: Print Importer Help Menus + run: bundle exec ruby script/cli_help_visualizer.rb diff --git a/script/cli_help_visualizer.rb b/script/cli_help_visualizer.rb new file mode 100644 index 00000000..a1458eac --- /dev/null +++ b/script/cli_help_visualizer.rb @@ -0,0 +1,38 @@ +require "bundler/setup" +require "jekyll-import" +require "mercenary" + +# The out-of-box Help output contains noise from * injected default options* such as +# `--help`, `--verbose`, etc in addition to options injected options from the `jekyll` +# executable. +# Therefore create a custom `Mercenary::Command` instances along with some monkey-patches +# to prettify output. + +module Mercenary + class Option + def to_s(justify_length=15) + "#{short.to_s.rjust(10)} #{long.ljust(justify_length)} #{description}" + end + end + + class Presenter + def command_options_presentation + c_opts = command.options + return nil if c_opts.empty? + + justify_length = c_opts.map { |o| o.long.length }.max + c_opts.map { |o| o.to_s(justify_length) }.join("\n") + end + end +end + +prog = Mercenary::Program.new(:jekyll).command(:import, &:itself) + +JekyllImport::Importer.subclasses.each do |importer| + puts "\n\n" + name = importer.to_s.split("::").last.downcase + cmd = Mercenary::Command.new(name, prog) + cmd.syntax "#{name} [options]" + importer.specify_options(cmd) + puts cmd +end