UNPKG

3.63 kBPlain TextView Raw
1#!/usr/bin/env node
2
3/**
4 * Command line interface of apeman.
5 * This file is auto generated by ape-tmpl.
6 */
7
8'use strict'
9
10const program = require('commander')
11const pkg = require('../package')
12const apeman = require('../lib')
13
14program
15 .version(pkg[ 'version' ])
16 .description('Meta application framework.')
17
18// Handling `api` command
19program
20 .command('api')
21 .description('')
22 .option('-p, --port <port>', 'Port number')
23 .option('-c, --configuration <configuration>', 'Pathname of Apemanfile')
24 .action((options) =>
25 apeman.api(options).catch(handleError)
26 )
27
28// Handling `doc` command
29program
30 .command('doc')
31 .description('Generate project documentation.')
32 .option('-o, --out <out>', 'Output directory path.')
33 .option('-c, --configuration <configuration>', 'Pathname of Apemanfile')
34 .option('-C, --context <context>', 'Pathname of mock context file.')
35 .action((options) =>
36 apeman.doc(options).catch(handleError)
37 )
38
39// Handling `init` command
40program
41 .command('init')
42 .description('Initialize a directory as an apeman project.')
43 .option('-f, --force', 'Force to init.')
44 .option('-d, --dirname <dirname>', 'Directory name to init.')
45 .option('-s, --silent', 'Disable console logs')
46 .option('-p, --pkg <pkg>', 'Path of package.json')
47 .action((options) =>
48 apeman.init(options).catch(handleError)
49 )
50
51// Handling `need` command
52program
53 .command('need')
54 .description('Check project needs.')
55 .option('-c, --configuration <configuration>', 'Pathname of Apemanfile')
56 .action((options) =>
57 apeman.need(options).catch(handleError)
58 )
59
60// Handling `scff` command
61program
62 .command('scff [type] [dest]')
63 .description('Generate project scaffold.')
64 .option('-t, --straight', 'Scaffold without asking.')
65 .option('-s, --silent', 'Disable console logs')
66 .option('-f, --force', 'Force to generate scaffold')
67 .action((type, dest, options) =>
68 apeman.scff(type, dest, options).catch(handleError)
69 )
70
71// Handling `srch` command
72program
73 .command('srch [term...]')
74 .description('Search apeman modules.')
75 .option('-v, --verbose', 'Show verbose logs')
76 .option('-t, --type <type>', 'Type to search.')
77 .action((term, options) =>
78 apeman.srch(term, options).catch(handleError)
79 )
80
81// Handling `show` command
82program
83 .command('show [keypath...]')
84 .description('Show apemanfile configuration.')
85 .option('-c, --configuration <configuration>', 'Pathname of Apemanfile')
86 .option('-k, --keysonly', 'Show keys only')
87 .action((keypath, options) =>
88 apeman.show(keypath, options).catch(handleError)
89 )
90
91// Handling `tree` command
92program
93 .command('tree')
94 .description('Show project inheritance in the tree.')
95 .option('-c, --configuration <configuration>', 'Pathname of Apemanfile')
96 .action((options) =>
97 apeman.tree(options).catch(handleError)
98 )
99
100// Handling `upg` command
101program
102 .command('upg')
103 .description('Update apeman global module.')
104 .option('-v, --verbose', 'Show verbose logs')
105 .action((options) =>
106 apeman.upg(options).catch(handleError)
107 )
108program.parse(process.argv)
109
110// Check sub command
111{
112 let command = process.argv[2]
113 if (!command) {
114 program.outputHelp()
115 return
116 }
117
118 let _isValid = name => {
119 for (let command of program.commands) {
120 let hit = (command.name() == name) || (command.alias() == name)
121 if(hit){
122 return true
123 }
124 }
125 return false
126 }
127 if (!_isValid(command)) {
128 console.log("[apeman] '%s' is not an apeman command. See 'apeman --help'.", command)
129 }
130
131}
132
133// Handlers
134
135/** Handle error */
136function handleError (err) {
137 console.error(err)
138 process.exit(1)
139}