Handles the command.
({fileEnvVariable, file, source}: Arguments<RestoreCommitMessageOptions>)
| 34 | |
| 35 | /** Handles the command. */ |
| 36 | async function handler({fileEnvVariable, file, source}: Arguments<RestoreCommitMessageOptions>) { |
| 37 | // File and source are provided as command line parameters |
| 38 | if (file !== undefined) { |
| 39 | restoreCommitMessage(file, source as CommitMsgSource); |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | // File and source are provided as values held in an environment variable. |
| 44 | if (fileEnvVariable !== undefined) { |
| 45 | const [fileFromEnv, sourceFromEnv] = (process.env[fileEnvVariable!] || '').split(' '); |
| 46 | if (!fileFromEnv) { |
| 47 | throw new Error(`Provided environment variable "${fileEnvVariable}" was not found.`); |
| 48 | } |
| 49 | restoreCommitMessage(fileFromEnv, sourceFromEnv as CommitMsgSource); |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | throw new Error( |
| 54 | 'No file path and commit message source provide. Provide values via positional command ' + |
| 55 | 'arguments, or via the --file-env-variable flag', |
| 56 | ); |
| 57 | } |
| 58 | |
| 59 | /** yargs command module describing the command. */ |
| 60 | export const RestoreCommitMessageModule: CommandModule<{}, RestoreCommitMessageOptions> = { |
nothing calls this directly
no test coverage detected