CoE CLI development adding a new command (Deprecated)
Note
The CoE CLI is deprecated and will be removed in a future release. Use the Power Platform Project Setup Wizard to set up and manage your ALM Accelerator for Power Platform projects.
To add a new sample command, you can use the following command to template the initial setup of the TypeScript command and the Jest JavaScript testing framework unit test.
cd coe-cli
coe cli add -n sample
Connecting the command to the command line
Once you have the unit test completed for your new command, perform these tasks:
Review https://www.npmjs.com/package/commander on commands, options.
Update commands.ts to include a new command or sub command.
- Import your files at the top of the file.
import { SampleArguments, SampleCommand} from './sample';
- Add a function for mock injection.
createSampleCommand: () => SampleCommand
- Create the command in the constructor function.
this.createSampleCommand = () => new SampleCommand
- Add the function.
AddSampleCommand(program: commander.Command) { var run = program.command('sample') .description('A new sample command') .option('-c, --comment <comment>', 'The comment for the command') .action(async (options: any) : Promise<void> => { let args = new SampleArguments(); args.comment = options.comment; let command = this.createSampleCommand(); await command.execute(args) }); }
- Register the new command to init function.
this.AddSampleCommand(program);
Update commands.spec.ts to include the unit tests.
- Include a reference to the command.
import { SampleCommand } from '../../src/commands/sample'
- Add a set of Jest tests.
describe('Sample', () => { test('Execute', async () => { // Arrange var commands = new CoeCliCommands(); let mockSampleCommand = mock<SampleCommand>(); commands.createSampleCommand = () => { return mockSampleCommand } mockSampleCommand.execute.mockResolvedValue() // Act await commands.execute(['node', 'commands.spec', 'sample', '-c', 'Some comment']) // Assert expect(mockSampleCommand.execute).toHaveBeenCalled() }) });
Run the unit tests with the new changes.
npm run test
Feedback
Submit and view feedback for