forked from fedwiki/wiki
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.coffee
More file actions
120 lines (111 loc) · 3.33 KB
/
cli.coffee
File metadata and controls
120 lines (111 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# **cli.coffee** command line interface for the
# Smallest-Federated-Wiki express server
path = require 'path'
optimist = require 'optimist'
cc = require 'config-chain'
glob = require 'glob'
server = require 'wiki-server'
farm = require './farm'
getUserHome = ->
process.env.HOME or process.env.HOMEPATH or process.env.USERPROFILE
# Handle command line options
argv = optimist
.usage('Usage: $0')
.options('url',
alias : 'u'
describe : 'Important: Your server URL, used as Persona audience during verification'
)
.options('port',
alias : 'p'
describe : 'Port'
)
.options('data',
alias : 'd'
describe : 'location of flat file data'
)
.options('root',
alias : 'r'
describe : 'Application root folder'
)
.options('farm',
alias : 'f'
describe : 'Turn on the farm?'
)
.options('farmPort',
alias : 'F'
describe : 'Port to start farm servers on.'
)
.options('home',
describe : 'The page to go to instead of index.html'
)
.options('host',
alias : 'o'
describe : 'Host to accept connections on, falsy == any'
)
.options('id',
describe : 'Set the location of the open id file'
)
.options('database',
describe : 'JSON object for database config'
)
.options('neighbors',
describe : 'comma separated list of neighbor sites to seed'
)
.options('autoseed',
describe : 'Seed all sites in a farm to each other site in the farm.'
boolean : true
)
.options('uploadLimit',
describe : 'Set the upload size limit, limits the size page content items, and pages that can be forked'
)
.options('test',
boolean : true
describe : 'Set server to work with the rspec integration tests'
)
.options('help',
alias : 'h'
boolean : true
describe : 'Show this help info and exit'
)
.options('config',
alias : 'conf'
describe : 'Optional config file.'
)
.options('version',
alias : 'v'
describe : 'Optional config file.'
)
.argv
config = cc(argv,
argv.config,
'config.json',
path.join(__dirname, '..', 'config.json'),
cc.env('wiki_'),
farmPort: 40000
port: 3000
root: path.dirname(require.resolve('wiki-server'))
home: 'welcome-visitors'
data: path.join(getUserHome(), '.wiki') # see also defaultargs
packageDir: path.resolve(path.join(__dirname, 'node_modules'))
).store
# If h/help is set print the generated help message and exit.
if argv.help
optimist.showHelp()
# If v/version is set print the version of the wiki components and exit.
else if argv.version
console.log('wiki: ' + require('./package').version)
console.log('wiki-server: ' + require('wiki-server/package').version)
console.log('wiki-client: ' + require('wiki-client/package').version)
glob 'wiki-plugin-*', {cwd: config.packageDir}, (e, plugins) ->
plugins.map (plugin) ->
console.log(plugin + ': ' + require(plugin + '/package').version)
else if argv.test
console.log "WARNING: Server started in testing mode, other options ignored"
server({port: 33333, data: path.join(argv.root, 'spec', 'data')})
# If f/farm is set call../lib/farm.coffee with argv object, else call
# ../lib/server.coffee with argv object.
else if config.farm
console.log('Wiki starting in Farm mode, navigate to a specific server to start it.')
farm(config)
else
server(config)