"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "dev-infra/commit-message/restore-commit-message/cli.ts" between
angular-11.0.1.tar.gz and angular-11.0.2.tar.gz

About: Angular is a development platform for building mobile and desktop web applications using Typescript/JavaScript.

cli.ts  (angular-11.0.1):cli.ts  (angular-11.0.2)
skipping to change at line 16 skipping to change at line 16
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {Arguments, Argv, CommandModule} from 'yargs'; import {Arguments, Argv, CommandModule} from 'yargs';
import {CommitMsgSource} from '../commit-message-source'; import {CommitMsgSource} from '../commit-message-source';
import {restoreCommitMessage} from './restore-commit-message'; import {restoreCommitMessage} from './restore-commit-message';
export interface RestoreCommitMessageOptions { export interface RestoreCommitMessageOptions {
fileEnvVariable: string[]; file?: string;
source?: string;
fileEnvVariable?: string;
} }
/** Builds the command. */ /** Builds the command. */
function builder(yargs: Argv) { function builder(yargs: Argv) {
return yargs.option('file-env-variable' as 'fileEnvVariable', { return yargs
type: 'string', .option('file-env-variable' as 'fileEnvVariable', {
array: true, type: 'string',
demandOption: true, description: 'The key for the environment variable which holds the argum
description: 'The key for the environment variable which holds the arguments ents for the\n' +
for the\n' + 'prepare-commit-msg hook as described here:\n' +
'prepare-commit-msg hook as described here:\n' + 'https://git-scm.com/docs/githooks#_prepare_commit_msg'
'https://git-scm.com/docs/githooks#_prepare_commit_msg', })
coerce: arg => { .positional('file', {type: 'string'})
const [file, source] = (process.env[arg] || '').split(' '); .positional('source', {type: 'string'});
if (!file) {
throw new Error(`Provided environment variable "${arg}" was not found.`)
;
}
return [file, source];
},
});
} }
/** Handles the command. */ /** Handles the command. */
async function handler({fileEnvVariable}: Arguments<RestoreCommitMessageOptions> async function handler({fileEnvVariable, file, source}: Arguments<RestoreCommitM
) { essageOptions>) {
restoreCommitMessage(fileEnvVariable[0], fileEnvVariable[1] as CommitMsgSource // File and source are provided as command line parameters
); if (file !== undefined) {
restoreCommitMessage(file, source as CommitMsgSource);
return;
}
// File and source are provided as values held in an environment variable.
if (fileEnvVariable !== undefined) {
const [fileFromEnv, sourceFromEnv] = (process.env[fileEnvVariable!] || '').s
plit(' ');
if (!fileFromEnv) {
throw new Error(`Provided environment variable "${fileEnvVariable}" was no
t found.`);
}
restoreCommitMessage(fileFromEnv, sourceFromEnv as CommitMsgSource);
return;
}
throw new Error(
'No file path and commit message source provide. Provide values via posit
ional command ' +
'arguments, or via the --file-env-variable flag');
} }
/** yargs command module describing the command. */ /** yargs command module describing the command. */
export const RestoreCommitMessageModule: CommandModule<{}, RestoreCommitMessageO ptions> = { export const RestoreCommitMessageModule: CommandModule<{}, RestoreCommitMessageO ptions> = {
handler, handler,
builder, builder,
command: 'restore-commit-message-draft', command: 'restore-commit-message-draft [file] [source]',
// Description: Restore a commit message draft if one has been saved from a fa iled commit attempt. // Description: Restore a commit message draft if one has been saved from a fa iled commit attempt.
// No describe is defiend to hide the command from the --help. // No describe is defiend to hide the command from the --help.
describe: false, describe: false,
}; };
 End of changes. 4 change blocks. 
23 lines changed or deleted 38 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)