Redundant provider registered subcommands
See original GitHub issueIs there an existing issue that is already proposing this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe it
Currently setup sub commands like followed by an example.
@SubCommand({
...
})
export class Sub {
...
}
@Command({
subCommands: [SubCommand]
})
export class Main {
...
}
import { Main } from './main.command'
import { Sub } from './sub.command'
@Module({
providers: [Main, Sub]
})
If we multiple nested some commands, every time must add them as providers to top module, and it looks redundant.
I always hack with spread operators
export const subcommands = [SubCommand]
@Command({
subCommands: subcommands
})
export class Main {
...
}
import { Main, subcommands } from './main.command'
@Module({
providers: [Main, ...subcommands]
})
export class AppModule {
}
but, even if using these manner, nested commands tough to manage by this.
Describe the solution you’d like
I suggest static register method in Command class and SubCommand class. This return [selfClass, …subcomand.regsiter()] which recursive register subcommand register method results. Then set module’s provider like that.
@SubCommand({
...
})
export class Sub {
...
}
@Command({
subCommands: [SubCommand]
})
export class Main {
...
}
import { Main } from './main.command'
@Module({
providers: Main.registerCommands() or [...Main.registerCommands()]
})
export class AppModule {
}
Teachability, documentation, adoption, migration strategy
This is not breaking changes because we can choice whether we use this method.
What is the motivation / use case for changing the behavior?
For effective reducing codes.
Issue Analytics
- State:
- Created 9 months ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Subcommands - Fortinet Documentation Library
Subcommands are available from within the scope of some commands. When you enter a subcommand level, the command prompt changes to indicate the...
Read more >Python Cement Subcommands with Arguments - Stack Overflow
As you can see, subcommand1 is presented as yet another subcommand to subcommand1, complete with redundant help text. Even if I omit the...
Read more >Commands S to Z - show crypto ace redundancy ... - Cisco
Version of the GET VPN software running on the GM. Registration status. Indicates whether the GM is registered with a KS. Registered with....
Read more >Oracle Unified Directory Command-Line Interface Reference
The following command displays the available global Help subcommands: ... base DNs of all directory servers defined in the registration information.
Read more >Command-Line Reference | Bazel
When enabled, redundant --defines will be removed early in the build. This avoids unnecessary loss of the analysis cache for certain types of ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I know I originally said that I probably wouldn’t add this in, but looking at the simplicity of the implementation and how it can be helpful, so long as it’s clear what the method does and it’s well documented, I think it would be fine to allow this. I’ve left a few comments on your PR.
@jmcdo29 Oh, sorry, I implemented this before I checked your reply.
I often use structure nested directory and not flat like
and they sometimes make me nervous if we use more nested commands in nested directories about how we know to export which commands though it can reduce complexity with barrel files. Though it doesn’t match your philosophy, but it can opt in and not influence other codebase. the usage is as hatch. In addition I couldn’t imagine the case we want to exclude subcommands set in metadata from providers.
If you do so, it’s okey for me, I’ll inherit your CommandRunner Class as you say. Thank you and sorry for spending your time.