Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/cli-test/src/cli/cli-process.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ describe('SlackCLIProcess class', () => {
);
spawnProcessSpy.resetHistory();
});
it('should map verbose option to `--verbose`', async () => {
let cmd = new SlackCLIProcess(['help'], { verbose: true });
await cmd.execAsync();
sandbox.assert.calledWith(spawnProcessSpy, sinon.match.string, sinon.match.array.contains(['--verbose']));
spawnProcessSpy.resetHistory();
cmd = new SlackCLIProcess(['help']);
await cmd.execAsync();
sandbox.assert.neverCalledWith(spawnProcessSpy, sinon.match.string, sinon.match.array.contains(['--verbose']));
});
});
describe('command options', () => {
it('should pass command-level key/value options to command in the form `--<key> value`', async () => {
Expand Down
5 changes: 5 additions & 0 deletions packages/cli-test/src/cli/cli-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export interface SlackCLIGlobalOptions {
team?: string;
/** @description Access token to use when making Slack API calls. */
token?: string;
/** @description Print debug logging and additional CLI information. */
verbose?: boolean;
}

export type SlackCLIHostTargetOptions = Pick<SlackCLIGlobalOptions, 'qa' | 'dev' | 'apihost'>;
Expand Down Expand Up @@ -144,6 +146,9 @@ export class SlackCLIProcess {
if (opts.token) {
cmd = cmd.concat(['--token', opts.token]);
}
if (opts.verbose) {
cmd = cmd.concat(['--verbose']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using concat alines with the syntax of this function and makes it readable, but looking at this line alone made me ask why push was not used instead 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC push and concat are doing similar things but with different returns and underlying happenings - instead of adding to the existing array, concat creates a new one and returns this as a value while push returns the new length instead 📚 ✨

FWIW I think push is a reasonable substitution, but concat gives me confidence in fewer side effects.

}
} else {
cmd = cmd.concat(['--skip-update', '--force', '--app', 'deployed']);
}
Expand Down
17 changes: 10 additions & 7 deletions packages/cli-test/src/cli/commands/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@ import {

import type { ShellProcess } from '../../types/shell';

type AuthLoginNoPromptArguments = SlackCLIHostTargetOptions & Pick<SlackCLIGlobalOptions, 'verbose'>;
type AuthLoginChallengeExchangeArugments = SlackCLIHostTargetOptions & {
/** @description Challenge string extracted from the Slack client UI after submitting the auth slash command. */
challenge: string;
/** @description The `authTicket` output from `loginNoPrompt`; required to complete the login flow. */
authTicket: string;
} & Pick<SlackCLIGlobalOptions, 'verbose'>;

export default {
/**
* `slack login --no-prompt`; initiates a CLI login flow. The `authTicketSlashCommand` returned should be entered
* into the Slack client, and the challenge code retrieved and fed into the `loginChallengeExchange` method to
* complete the CLI login flow.
*/
loginNoPrompt: async function loginNoPrompt(args?: SlackCLIHostTargetOptions): Promise<{
loginNoPrompt: async function loginNoPrompt(args?: AuthLoginNoPromptArguments): Promise<{
/** @description Command output */
output: ShellProcess['output'];
/**
Expand Down Expand Up @@ -57,12 +65,7 @@ export default {
* @returns
*/
loginChallengeExchange: async function loginChallengeExchange(
args: SlackCLIHostTargetOptions & {
/** @description Challenge string extracted from the Slack client UI after submitting the auth slash command. */
challenge: string;
/** @description The `authTicket` output from `loginNoPrompt`; required to complete the login flow. */
authTicket: string;
},
args: AuthLoginChallengeExchangeArugments,
): Promise<string> {
const cmd = new SlackCLIProcess(['login'], args, {
'--no-prompt': true,
Expand Down