Skip to content

Commit

Permalink
Handle initial help argument when applied to subcommand methods
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyates committed May 12, 2023
1 parent bf58df7 commit 0a0ef77
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## 9.3.1 - 2023-05-12

## Changed

* Previously, when help was requested on a subcommand method,
the output was of listing all subcommand methods.
Now, the output is now the help for that specific method.

## 9.2.0 - 2023-03-01

## Changed
Expand Down
15 changes: 15 additions & 0 deletions lib/imap/backup/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ class CLI < Thor

default_task :backup

def self.start(*args)
# By default, commands like `imap-backup help foo bar`
# are handled by listing all `foo` methods, whereas the user
# probably wants the detailed help for the `bar` method.
# Move initial "help" argument to after any subcommand,
# so we get help for the requested subcommand method.
first_argument_is_help = ARGV[0] == "help"
second_argument_is_subcommand = subcommands.include?(ARGV[1])
if first_argument_is_help && second_argument_is_subcommand
help, subcommand = ARGV.shift(2)
ARGV.unshift(subcommand, help)
end
super
end

def self.exit_on_failure?
true
end
Expand Down
2 changes: 1 addition & 1 deletion lib/imap/backup/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Imap; end
module Imap::Backup
MAJOR = 9
MINOR = 3
REVISION = 0
REVISION = 1
PRE = nil
VERSION = [MAJOR, MINOR, REVISION, PRE].compact.map(&:to_s).join(".")
end
11 changes: 11 additions & 0 deletions spec/features/help_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require "features/helper"

RSpec.describe "imap-backup help", type: :aruba do
context "when subcommands are invoked with a method" do
it "outputs the method's help" do
run_command_and_stop "imap-backup help remote namespaces"

expect(last_command_started).to have_output(/Options:/)
end
end
end

0 comments on commit 0a0ef77

Please sign in to comment.