Skip to content

Commit

Permalink
Adds help messages to the help command
Browse files Browse the repository at this point in the history
- Closes #87
  • Loading branch information
andreban committed Jan 29, 2020
1 parent b6c61c8 commit f859c4d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
53 changes: 52 additions & 1 deletion src/cli/cmds/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,57 @@
* limitations under the License.
*/

export async function help(): Promise<void> {
import Log from '../../lib/Log';
import {ParsedArgs} from 'minimist';

const HELP_MESSAGES = new Map<string, string>(
[
['main', [
'llama-pack [command] <options>',
'',
'',
'build ............... generates an Android APK from a TWA Project',
'help ................ shows this menu',
'init ................ initializes a new TWA Project',
'update .............. updates an existing TWA Project with the latest llama-pack template',
].join('\n')],
['init', [
'Usage:',
'',
'',
'lama-pack init --manifest=[web-manifest-url]',
'',
'',
'Options:',
'--directory ......... path where to generate the project. Defaults to the current' +
' directory',
].join('\n')],
['build', [
'Usage:',
'',
'',
'llama-pack build',
].join('\n')],
['update', [
'Usage:',
'',
'',
'llama-pack update',
].join('\n')],
],
);

export async function help(args: ParsedArgs, log = new Log('help')): Promise<void> {
// minimist uses an `_` object to store details.
const command = args._[1];
const message = HELP_MESSAGES.get(command) || HELP_MESSAGES.get('main');

// Should never happen, as we know we have a message for Command.main,
// but TypeScript doesn't know it.
if (message === undefined) {
log.error(`Could not find help message for args: ${args}`);
return;
}
log.info(message);
return;
}
2 changes: 1 addition & 1 deletion src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class Cli {
const command = args[0] || 'help';
switch (command) {
case 'help':
return await help();
return await help(parsedArgs);
case 'init':
return await init(parsedArgs, config);
case 'update':
Expand Down

0 comments on commit f859c4d

Please sign in to comment.