@@ -9,14 +9,26 @@ class CLI
9
9
# @since 0.1.0
10
10
# @api private
11
11
module Banner
12
- # Prints command banner
12
+ # Prints command/namespace banner
13
13
#
14
- # @param command [Dry::CLI::Command] the command
14
+ # @param command [Dry::CLI::Command, Dry::CLI::Namespace ] the command/namespace
15
15
# @param out [IO] standard output
16
16
#
17
17
# @since 0.1.0
18
18
# @api private
19
19
def self . call ( command , name )
20
+ b = if CLI . command? ( command )
21
+ command_banner ( command , name )
22
+ else
23
+ namespace_banner ( command , name )
24
+ end
25
+
26
+ b . compact . join ( "\n " )
27
+ end
28
+
29
+ # @since 1.1.1
30
+ # @api private
31
+ def self . command_banner ( command , name )
20
32
[
21
33
command_name ( name ) ,
22
34
command_name_and_arguments ( command , name ) ,
@@ -25,13 +37,25 @@ def self.call(command, name)
25
37
command_arguments ( command ) ,
26
38
command_options ( command ) ,
27
39
command_examples ( command , name )
28
- ] . compact . join ( "\n " )
40
+ ]
41
+ end
42
+
43
+ # @since 1.1.1
44
+ # @api private
45
+ def self . namespace_banner ( namespace , name )
46
+ [
47
+ command_name ( name , "Namespace" ) ,
48
+ command_name_and_arguments ( namespace , name ) ,
49
+ command_description ( namespace ) ,
50
+ command_subcommands ( namespace , "Commands" ) ,
51
+ command_options ( namespace )
52
+ ]
29
53
end
30
54
31
55
# @since 0.1.0
32
56
# @api private
33
- def self . command_name ( name )
34
- "Command :\n #{ name } "
57
+ def self . command_name ( name , label = "Command" )
58
+ "#{ label } :\n #{ name } "
35
59
end
36
60
37
61
# @since 0.1.0
@@ -70,10 +94,10 @@ def self.command_description(command)
70
94
"\n Description:\n #{ command . description } "
71
95
end
72
96
73
- def self . command_subcommands ( command )
97
+ def self . command_subcommands ( command , label = "Subcommands" )
74
98
return if command . subcommands . empty?
75
99
76
- "\n Subcommands :\n #{ build_subcommands_list ( command . subcommands ) } "
100
+ "\n #{ label } :\n #{ build_subcommands_list ( command . subcommands ) } "
77
101
end
78
102
79
103
# @since 0.1.0
0 commit comments