File tree Expand file tree Collapse file tree 6 files changed +34
-9
lines changed Expand file tree Collapse file tree 6 files changed +34
-9
lines changed Original file line number Diff line number Diff line change @@ -31,15 +31,16 @@ def self.call(result)
3131 def self . commands_and_arguments ( result )
3232 max_length = 0
3333 ret = commands ( result ) . each_with_object ( { } ) do |( name , node ) , memo |
34- args = if node . command && node . leaf? && node . children?
35- ROOT_COMMAND_WITH_SUBCOMMANDS_BANNER
36- elsif node . leaf?
37- arguments ( node . command )
38- else
39- SUBCOMMAND_BANNER
40- end
41-
42- partial = " #{ command_name ( result , name ) } #{ args } "
34+ args = arguments ( node . command )
35+ args_banner = if node . command && node . leaf? && node . children? && args
36+ ROOT_COMMAND_WITH_SUBCOMMANDS_BANNER
37+ elsif node . leaf? && args
38+ args
39+ elsif node . children?
40+ SUBCOMMAND_BANNER
41+ end
42+
43+ partial = " #{ command_name ( result , name ) } #{ args_banner } "
4344 max_length = partial . bytesize if max_length < partial . bytesize
4445 memo [ partial ] = node
4546 end
Original file line number Diff line number Diff line change @@ -438,6 +438,18 @@ def call(**params)
438438 end
439439 end
440440
441+ class Namespace < Dry ::CLI ::Command
442+ desc "This is a namespace"
443+
444+ class SubCommand < Dry ::CLI ::Command
445+ desc "I'm a concrete command"
446+
447+ def call ( **params )
448+ puts "I'm a concrete command"
449+ end
450+ end
451+ end
452+
441453 class InitializedCommand < Dry ::CLI ::Command
442454 attr_reader :prop
443455
Original file line number Diff line number Diff line change 2222 cli . register "root-command" , Commands ::RootCommand do |prefix |
2323 prefix . register "sub-command" , Commands ::RootCommands ::SubCommand
2424 end
25+ cli . register "namespace" , Commands ::Namespace do |prefix |
26+ prefix . register "sub-command" , Commands ::Namespace ::SubCommand
27+ end
2528
2629 cli . register "options-with-aliases" , Commands ::OptionsWithAliases
2730 cli . register "variadic default" , Commands ::VariadicArguments
Original file line number Diff line number Diff line change @@ -58,6 +58,8 @@ module Commands
5858 register "with-initializer" , ::Commands ::InitializedCommand . new ( prop : "prop_val" )
5959 register "root-command" , ::Commands ::RootCommand
6060 register "root-command sub-command" , ::Commands ::RootCommands ::SubCommand
61+ register "namespace" , ::Commands ::Namespace
62+ register "namespace sub-command" , ::Commands ::Namespace ::SubCommand
6163
6264 register "options-with-aliases" , ::Commands ::OptionsWithAliases
6365 register "variadic default" , ::Commands ::VariadicArguments
Original file line number Diff line number Diff line change 2323 register "root-command" do
2424 register "sub-command" , Commands ::RootCommands ::SubCommand
2525 end
26+ register "namespace" , Commands ::Namespace
27+ register "namespace" do
28+ register "sub-command" , Commands ::Namespace ::SubCommand
29+ end
2630
2731 register "options-with-aliases" , Commands ::OptionsWithAliases
2832 register "variadic default" , Commands ::VariadicArguments
Original file line number Diff line number Diff line change 1919 #{ cmd } greeting [RESPONSE]
2020 #{ cmd } hello # Print a greeting
2121 #{ cmd } inherited [SUBCOMMAND]
22+ #{ cmd } namespace [SUBCOMMAND] # This is a namespace
2223 #{ cmd } new PROJECT # Generate a new Foo project
2324 #{ cmd } options-with-aliases # Accepts options with aliases
2425 #{ cmd } root-command [ARGUMENT|SUBCOMMAND] # Root command with arguments and subcommands
8081 #{ cmd } greeting [RESPONSE]
8182 #{ cmd } hello # Print a greeting
8283 #{ cmd } inherited [SUBCOMMAND]
84+ #{ cmd } namespace [SUBCOMMAND] # This is a namespace
8385 #{ cmd } new PROJECT # Generate a new Foo project
8486 #{ cmd } options-with-aliases # Accepts options with aliases
8587 #{ cmd } root-command [ARGUMENT|SUBCOMMAND] # Root command with arguments and subcommands
109111 #{ cmd } greeting [RESPONSE]
110112 #{ cmd } hello # Print a greeting
111113 #{ cmd } inherited [SUBCOMMAND]
114+ #{ cmd } namespace [SUBCOMMAND] # This is a namespace
112115 #{ cmd } new PROJECT # Generate a new Foo project
113116 #{ cmd } options-with-aliases # Accepts options with aliases
114117 #{ cmd } root-command [ARGUMENT|SUBCOMMAND] # Root command with arguments and subcommands
You can’t perform that action at this time.
0 commit comments