question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Redundant provider registered subcommands

See original GitHub issue

Is 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:open
  • Created 9 months ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jmcdo29commented, Dec 25, 2022

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.

0reactions
tkowcommented, Dec 24, 2022

@jmcdo29 Oh, sorry, I implemented this before I checked your reply.

I often use structure nested directory and not flat like

   --user/(barrel)index.ts,command.1.ts,command.2.ts 
   --post/(barrel)index.ts,command.1.ts,command.2.ts 
   --review/(barrel)index.ts,command.1.ts,command.2.ts

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.

I don’t think it’s something I want to add to the library

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found