1- import { Injectable } from '@nestjs/common' ;
1+ import { Injectable , Optional } from '@nestjs/common' ;
22import { CliService } from './modules/cli/cli.service' ;
33import { NodeVersionService } from './modules/node-version/node.version.service' ;
44import { INodeVersion } from './modules/node-version/interfaces' ;
@@ -13,7 +13,7 @@ import { PresentationMode } from './modules/presenter/interfaces';
1313export class AppService {
1414
1515 constructor (
16- private cliService : CliService ,
16+ @ Optional ( ) private cliService : CliService ,
1717 private presenterService : PresenterService ,
1818 private rateLimitService : RateLimitService ,
1919 private nodeVersionService : NodeVersionService ,
@@ -24,19 +24,23 @@ export class AppService {
2424 public async main ( ) {
2525 const options : IProgramOptions = await this . cliService . getProgramOptions ( ) ;
2626
27+ return this . run ( options ) ;
28+ }
29+
30+ public async run ( options : IProgramOptions ) {
2731 this . setupPresenter ( options ) ;
2832
2933 this . presenterService . showFiglet ( ) ;
3034 this . presenterService . showGithubTokenInfo ( options ) ;
3135
32- const { package : packageName , node, rateLimit } = options ;
36+ const { package : packageName , node, rateLimit, token } = options ;
3337
3438 if ( node ) {
3539 return this . nodeCase ( options ) ;
3640 } else if ( packageName ) {
3741 return this . packageCase ( options ) ;
3842 } else if ( rateLimit ) {
39- return this . showRateLimit ( true ) ;
43+ return this . showRateLimit ( true , token ) ;
4044 } else {
4145 this . presenterService . showError ( 'Wrong input' ) ;
4246 }
@@ -45,17 +49,17 @@ export class AppService {
4549 private async nodeCase ( options : IProgramOptions ) {
4650 const report : INodeVersion [ ] = await this . nodeVersionService . getReport ( options ) ;
4751 this . presenterService . showData ( report , options ) ;
48- this . showRateLimit ( false ) ;
52+ this . showRateLimit ( false , options . token ) ;
4953 }
5054
5155 private async packageCase ( options : IProgramOptions ) {
5256 const report : IPacakgeVersion [ ] = await this . npmDependencyVersionService . getReport ( options ) ;
5357 this . presenterService . showData ( report , options ) ;
54- this . showRateLimit ( false ) ;
58+ this . showRateLimit ( false , options . token ) ;
5559 }
5660
57- private async showRateLimit ( isMainInfo : boolean ) {
58- const rateLimit = await this . rateLimitService . getRateLimit ( ) ;
61+ private async showRateLimit ( isMainInfo : boolean , token ?: string ) {
62+ const rateLimit = await this . rateLimitService . getRateLimit ( token ) ;
5963
6064 this . presenterService . showRateLimit ( rateLimit , isMainInfo ) ;
6165 }
0 commit comments