From a54951b29eb970732c7059cd8288b76670482cf8 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Mon, 28 Nov 2022 15:40:03 +0530 Subject: [PATCH 1/2] Add CI workflow job to print importer help info --- .github/workflows/ci.yml | 20 ++++++++++++++++++++ script/cli_help_check.rb | 8 ++++++++ 2 files changed, 28 insertions(+) create mode 100644 script/cli_help_check.rb diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6a833dd2..f377536b 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_check: + name: "CLI Help Info Check" + 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_check.rb diff --git a/script/cli_help_check.rb b/script/cli_help_check.rb new file mode 100644 index 00000000..5ab49297 --- /dev/null +++ b/script/cli_help_check.rb @@ -0,0 +1,8 @@ +require "bundler/setup" +require "jekyll-import" + +JekyllImport::Importer.subclasses.each do |importer| + name = importer.to_s.split("::").last.downcase + puts "\n\n" + system "jekyll", "import", name, "--help" +end From c0603d89763662c08ddb551b488a503642a0e9fb Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Mon, 28 Nov 2022 16:10:45 +0530 Subject: [PATCH 2/2] Print customized help output --- .github/workflows/ci.yml | 6 +++--- script/cli_help_check.rb | 8 -------- script/cli_help_visualizer.rb | 38 +++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 11 deletions(-) delete mode 100644 script/cli_help_check.rb create mode 100644 script/cli_help_visualizer.rb diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f377536b..6c86923a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,8 +53,8 @@ jobs: - name: Run RuboCop run: bash script/fmt - cli_help_check: - name: "CLI Help Info Check" + cli_help_info_visualization: + name: "CLI Help Info Visualization" runs-on: "ubuntu-latest" strategy: fail-fast: false @@ -71,4 +71,4 @@ jobs: ruby-version: ${{ matrix.ruby_version }} bundler-cache: true - name: Print Importer Help Menus - run: bundle exec ruby script/cli_help_check.rb + run: bundle exec ruby script/cli_help_visualizer.rb diff --git a/script/cli_help_check.rb b/script/cli_help_check.rb deleted file mode 100644 index 5ab49297..00000000 --- a/script/cli_help_check.rb +++ /dev/null @@ -1,8 +0,0 @@ -require "bundler/setup" -require "jekyll-import" - -JekyllImport::Importer.subclasses.each do |importer| - name = importer.to_s.split("::").last.downcase - puts "\n\n" - system "jekyll", "import", name, "--help" -end 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