Skip to content

Commit 5799866

Browse files
Extract method
1 parent 04d7560 commit 5799866

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

lib/thor/command.rb

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,7 @@ def formatted_usage(klass, namespace = true, subcommand = false)
4949

5050
formatted ||= "".dup
5151

52-
# Add usage with required arguments
53-
formatted << if klass && !klass.arguments.empty?
54-
usage.to_s.gsub(/^#{name}/) do |match|
55-
match << " " << klass.arguments.map(&:usage).compact.join(" ")
56-
end
57-
else
58-
usage.to_s
59-
end
52+
formatted << required_arguments_for(klass, specific_usage)
6053

6154
# Add required options
6255
formatted << " #{required_options}"
@@ -67,6 +60,17 @@ def formatted_usage(klass, namespace = true, subcommand = false)
6760

6861
protected
6962

63+
# Add usage with required arguments
64+
def required_arguments_for(klass, usage)
65+
if klass && !klass.arguments.empty?
66+
usage.to_s.gsub(/^#{name}/) do |match|
67+
match << " " << klass.arguments.map(&:usage).compact.join(" ")
68+
end
69+
else
70+
usage.to_s
71+
end
72+
end
73+
7074
def not_debugging?(instance)
7175
!(instance.class.respond_to?(:debugging) && instance.class.debugging)
7276
end

0 commit comments

Comments
 (0)