fix(core): update
This commit is contained in:
		
							
								
								
									
										33
									
								
								test/test.ts
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								test/test.ts
									
									
									
									
									
								
							@@ -3,41 +3,40 @@ import { Subject } from 'rxjs';
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import * as smartcli from '../ts/index.js';
 | 
					import * as smartcli from '../ts/index.js';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
let smartCliTestObject: smartcli.Smartcli;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
tap.test('should create a new Smartcli', async () => {
 | 
					tap.test('should create a new Smartcli', async () => {
 | 
				
			||||||
  smartCliTestObject = new smartcli.Smartcli();
 | 
					  const smartCliTestObject = new smartcli.Smartcli();
 | 
				
			||||||
  expect(smartCliTestObject).toBeInstanceOf(smartcli.Smartcli);
 | 
					  expect(smartCliTestObject).toBeInstanceOf(smartcli.Smartcli);
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
tap.test('should add an command', async () => {
 | 
					tap.test('should add an command', async (toolsArg) => {
 | 
				
			||||||
  expect(smartCliTestObject.addCommand('awesome')).toBeInstanceOf(Subject);
 | 
					  const done = toolsArg.defer();
 | 
				
			||||||
 | 
					  const smartCliTestObject = new smartcli.Smartcli();
 | 
				
			||||||
 | 
					  const awesomeCommandSubject = smartCliTestObject.addCommand('awesome')
 | 
				
			||||||
 | 
					  expect(awesomeCommandSubject).toBeInstanceOf(Subject);
 | 
				
			||||||
 | 
					  awesomeCommandSubject.subscribe(() => {
 | 
				
			||||||
 | 
					    done.resolve();
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					  console.log(process.argv);
 | 
				
			||||||
 | 
					  process.argv.splice(2, 0, 'awesome');
 | 
				
			||||||
 | 
					  console.log(process.argv);
 | 
				
			||||||
 | 
					  smartCliTestObject.startParse();
 | 
				
			||||||
 | 
					  await done.promise;
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
tap.test('should start parsing a standardTask', async () => {
 | 
					tap.test('should start parsing a standardTask', async () => {
 | 
				
			||||||
 | 
					  const smartCliTestObject = new smartcli.Smartcli();
 | 
				
			||||||
  expect(smartCliTestObject.standardCommand()).toBeInstanceOf(Subject);
 | 
					  expect(smartCliTestObject.standardCommand()).toBeInstanceOf(Subject);
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
let hasExecuted: boolean = false;
 | 
					let hasExecuted: boolean = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
tap.test('should accept a command', async () => {
 | 
					tap.test('should accept a command', async () => {
 | 
				
			||||||
 | 
					  const smartCliTestObject = new smartcli.Smartcli();
 | 
				
			||||||
  smartCliTestObject.addCommand('triggerme').subscribe(() => {
 | 
					  smartCliTestObject.addCommand('triggerme').subscribe(() => {
 | 
				
			||||||
    hasExecuted = true;
 | 
					    hasExecuted = true;
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
tap.test('should not have executed yet', async () => {
 | 
					 | 
				
			||||||
  expect(hasExecuted).toBeFalse();
 | 
					 | 
				
			||||||
});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
tap.test('should execute when triggered', async () => {
 | 
					 | 
				
			||||||
  smartCliTestObject.triggerCommand('triggerme', {});
 | 
					  smartCliTestObject.triggerCommand('triggerme', {});
 | 
				
			||||||
  expect(hasExecuted).toBeTrue();
 | 
					  expect(hasExecuted).toBeTrue();
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
tap.test('should start parsing the CLI input', async () => {
 | 
					 | 
				
			||||||
  smartCliTestObject.startParse();
 | 
					 | 
				
			||||||
  expect(smartCliTestObject.parseCompleted.promise).toBeInstanceOf(Promise);
 | 
					 | 
				
			||||||
});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
tap.start();
 | 
					tap.start();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,6 +3,6 @@
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
export const commitinfo = {
 | 
					export const commitinfo = {
 | 
				
			||||||
  name: '@pushrocks/smartcli',
 | 
					  name: '@pushrocks/smartcli',
 | 
				
			||||||
  version: '4.0.1',
 | 
					  version: '4.0.2',
 | 
				
			||||||
  description: 'easy observable cli tasks'
 | 
					  description: 'easy observable cli tasks'
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,7 +18,6 @@ export class Smartcli {
 | 
				
			|||||||
  public parseCompleted = plugins.smartpromise.defer<any>();
 | 
					  public parseCompleted = plugins.smartpromise.defer<any>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public version: string;
 | 
					  public version: string;
 | 
				
			||||||
  private checkForEnvCliCall = true;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * map of all Trigger/Observable objects to keep track
 | 
					   * map of all Trigger/Observable objects to keep track
 | 
				
			||||||
@@ -35,13 +34,6 @@ export class Smartcli {
 | 
				
			|||||||
   */
 | 
					   */
 | 
				
			||||||
  constructor() {}
 | 
					  constructor() {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					 | 
				
			||||||
   * halts any execution of commands if (process.env.CLI_CALL === false)
 | 
					 | 
				
			||||||
   */
 | 
					 | 
				
			||||||
  disableEnvCliCall() {
 | 
					 | 
				
			||||||
    this.checkForEnvCliCall = false;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * adds an alias, meaning one equals the other in terms of command execution.
 | 
					   * adds an alias, meaning one equals the other in terms of command execution.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
@@ -123,19 +115,12 @@ export class Smartcli {
 | 
				
			|||||||
   * start the process of evaluating commands
 | 
					   * start the process of evaluating commands
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  public startParse(): void {
 | 
					  public startParse(): void {
 | 
				
			||||||
    // if we check for cli env calls, we might want to abort here.
 | 
					 | 
				
			||||||
    if (!process.env.CLI_CALL && this.checkForEnvCliCall) {
 | 
					 | 
				
			||||||
      console.log(
 | 
					 | 
				
			||||||
        `note: @pushrocks/smartcli: You called .startParse() on a SmartCli instance. However process.env.CLI_CALL being absent prevented parsing.`
 | 
					 | 
				
			||||||
      );
 | 
					 | 
				
			||||||
      return;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    const parsedYArgs = plugins.yargsParser(process.argv);
 | 
					    const parsedYArgs = plugins.yargsParser(process.argv);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // lets handle commands
 | 
					    // lets handle commands
 | 
				
			||||||
    let counter = 0;
 | 
					    let counter = 0;
 | 
				
			||||||
    let foundCommand = false;
 | 
					    let foundCommand = false;
 | 
				
			||||||
    parsedYArgs._.map((commandPartArg) => {
 | 
					    parsedYArgs._ = parsedYArgs._.filter((commandPartArg) => {
 | 
				
			||||||
      counter++;
 | 
					      counter++;
 | 
				
			||||||
      if (typeof commandPartArg === 'number') {
 | 
					      if (typeof commandPartArg === 'number') {
 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
@@ -149,7 +134,8 @@ export class Smartcli {
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    for (const command of this.commandObservableMap.getArray()) {
 | 
					    for (const command of this.commandObservableMap.getArray()) {
 | 
				
			||||||
      if (!parsedYArgs._[0]) {
 | 
					      const wantedCommand = parsedYArgs._[0];
 | 
				
			||||||
 | 
					      if (!wantedCommand) {
 | 
				
			||||||
        const standardCommand = this.commandObservableMap.findSync((commandArg) => {
 | 
					        const standardCommand = this.commandObservableMap.findSync((commandArg) => {
 | 
				
			||||||
          return commandArg.commandName === 'standardCommand';
 | 
					          return commandArg.commandName === 'standardCommand';
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
@@ -160,6 +146,7 @@ export class Smartcli {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					      console.log(`Wanted command: ${wantedCommand}`);
 | 
				
			||||||
      if (command.commandName === parsedYArgs._[0]) {
 | 
					      if (command.commandName === parsedYArgs._[0]) {
 | 
				
			||||||
        command.subject.next(parsedYArgs);
 | 
					        command.subject.next(parsedYArgs);
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user