Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI workflow job to print importer help info #497

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
38 changes: 38 additions & 0 deletions script/cli_help_visualizer.rb
Original file line number Diff line number Diff line change
@@ -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