/
ghenv.js
executable file
·148 lines (141 loc) · 3.84 KB
/
ghenv.js
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env node
'use strict'
const { terminalWidth } = require('yargs')
const { hideBin } = require('yargs/helpers')
const yargs = require('yargs/yargs')
const { view, read, write, list, explain } = require('./lib/commands')
const { NAME, hostPkg } = require('./lib/const')
const log = require('./lib/log')
const {
setup,
setupLogging,
setupConfig,
} = require('./lib/middleware')
const { tryLoadConfig } = require('./lib/util')
yargs(hideBin(process.argv))
.middleware([setupLogging, setupConfig, setup])
.config(tryLoadConfig())
.option('repository', {
group: 'Global Options:',
description:
'The name of the repository where to store the processed files. It can be a simple name, in which case the authenticated user account is assumed to be the owner, or in the form {owner}/{name}',
default: `.${NAME}`,
})
.option('pattern', {
group: 'Global Options:',
description: 'The pattern to use to match files to include',
default: '**/.env',
})
.option('file-name', {
group: 'Global Options:',
description:
'The name of the file to store in the repository. Defaults to the name of the package as specified in package.json',
default: hostPkg.name,
})
.option('verbose', {
alias: 'v',
count: true,
description:
'Increases the level of verbosity of the output. Can be applied multiple times to increase verbosity, e.g. -vv',
})
.option('force-create-key', {
group: 'Advanced Options:',
alias: 'C',
boolean: true,
description: 'Forces the creation of a new encryption key',
})
.option('force-download-key', {
group: 'Advanced Options:',
alias: 'D',
boolean: true,
description: 'Forces the download of the encryption key',
})
.option('force-create-workflow', {
group: 'Advanced Options:',
alias: 'W',
boolean: true,
description: 'Forces the creation of the workflow',
})
.command(
'write',
'Writes the local files to the remote archive',
yargs =>
yargs.option('message', {
group: 'Command Options:',
alias: 'm',
requiresArg: true,
description:
'Optional commit message. Placeholder %s is replaced with the name of the file',
}),
write
)
.command(
'read',
'Reads the remote archive and writes to the local file system, creating new files or overwriting existing ones',
() => {},
read
)
.command(
['list', 'ls'],
'Lists the files that will be processed. Defaults to showing the local files',
yargs =>
yargs.option('remote', {
group: 'Command Options:',
alias: 'r',
boolean: true,
default: false,
description:
'When provided, lists remote files instead of the local ones',
}),
list
)
.command(
'view',
'View the contents of the files. Defaults to showing the local files',
yargs =>
yargs.option('remote', {
group: 'Command Options:',
alias: 'r',
boolean: true,
default: false,
description:
'When provided, shows the contents of the remote files instead of the local ones',
}),
view
)
.command(
'explain',
'Shows the configuration options that will be used by commands',
() => {},
explain
)
.command(
'debug',
false,
yargs =>
yargs.option('remote', {
group: 'Command Options:',
alias: 'r',
boolean: true,
default: false,
description:
'When provided, performs remote inizialization before outputting debug information',
}),
console.log
)
.demandCommand()
.strict()
.fail(function (msg, err, yargs) {
if (msg) {
log.warn(msg)
}
if (err) {
log.error(log.isDebug ? err.stack : err)
}
if (msg) {
log()
yargs.showHelp()
}
process.exit(1)
})
.wrap(terminalWidth()).argv