Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
彭彦祖
code-server
提交
8053ec68
C
code-server
项目概览
彭彦祖
/
code-server
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
code-server
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
8053ec68
编写于
5月 19, 2020
作者:
A
Anmol Sethi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow user-data-dir and extension-dir in config.yaml
Closes #1676
上级
aa872701
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
58 addition
and
52 deletion
+58
-52
src/node/cli.ts
src/node/cli.ts
+13
-3
src/node/entry.ts
src/node/entry.ts
+5
-3
test/cli.test.ts
test/cli.test.ts
+40
-46
未找到文件。
src/node/cli.ts
浏览文件 @
8053ec68
...
...
@@ -152,12 +152,12 @@ export const optionDescriptions = (): string[] => {
)
}
export
const
parse
=
async
(
export
const
parse
=
(
argv
:
string
[],
opts
?:
{
configFile
:
string
},
):
Promise
<
Args
>
=>
{
):
Args
=>
{
const
error
=
(
msg
:
string
):
Error
=>
{
if
(
opts
?.
configFile
)
{
msg
=
`error reading
${
opts
.
configFile
}
:
${
msg
}
`
...
...
@@ -288,18 +288,28 @@ export const parse = async (
break
case
LogLevel
.
Debug
:
logger
.
level
=
Level
.
Debug
args
.
verbose
=
false
break
case
LogLevel
.
Info
:
logger
.
level
=
Level
.
Info
args
.
verbose
=
false
break
case
LogLevel
.
Warn
:
logger
.
level
=
Level
.
Warning
args
.
verbose
=
false
break
case
LogLevel
.
Error
:
logger
.
level
=
Level
.
Error
args
.
verbose
=
false
break
}
return
args
}
export
async
function
setDefaults
(
args
:
Args
):
Promise
<
Args
>
{
args
=
{
...
args
}
if
(
!
args
[
"
user-data-dir
"
])
{
await
copyOldMacOSDataDir
()
args
[
"
user-data-dir
"
]
=
paths
.
data
...
...
@@ -353,7 +363,7 @@ export async function readConfigFile(configPath?: string): Promise<Args> {
}
return
`--
${
optName
}
=
${
opt
}
`
})
const
args
=
await
parse
(
configFileArgv
,
{
const
args
=
parse
(
configFileArgv
,
{
configFile
:
configPath
,
})
return
{
...
...
src/node/entry.ts
浏览文件 @
8053ec68
...
...
@@ -9,7 +9,7 @@ import { ProxyHttpProvider } from "./app/proxy"
import
{
StaticHttpProvider
}
from
"
./app/static
"
import
{
UpdateHttpProvider
}
from
"
./app/update
"
import
{
VscodeHttpProvider
}
from
"
./app/vscode
"
import
{
Args
,
bindAddrFromAllSources
,
optionDescriptions
,
parse
,
readConfigFile
}
from
"
./cli
"
import
{
Args
,
bindAddrFromAllSources
,
optionDescriptions
,
parse
,
readConfigFile
,
setDefaults
}
from
"
./cli
"
import
{
AuthType
,
HttpServer
,
HttpServerOptions
}
from
"
./http
"
import
{
generateCertificate
,
hash
,
open
,
humanPath
}
from
"
./util
"
import
{
ipcMain
,
wrap
}
from
"
./wrapper
"
...
...
@@ -43,6 +43,8 @@ const main = async (cliArgs: Args): Promise<void> => {
}
}
args
=
await
setDefaults
(
args
)
logger
.
info
(
`Using user-data-dir
${
humanPath
(
args
[
"
user-data-dir
"
])}
`
)
logger
.
trace
(
`Using extensions-dir
${
humanPath
(
args
[
"
extensions-dir
"
])}
`
)
...
...
@@ -127,9 +129,9 @@ const main = async (cliArgs: Args): Promise<void> => {
}
async
function
entry
():
Promise
<
void
>
{
const
tryParse
=
async
():
Promise
<
Args
>
=>
{
const
tryParse
=
():
Args
=>
{
try
{
return
await
parse
(
process
.
argv
.
slice
(
2
))
return
parse
(
process
.
argv
.
slice
(
2
))
}
catch
(
error
)
{
console
.
error
(
error
.
message
)
process
.
exit
(
1
)
...
...
test/cli.test.ts
浏览文件 @
8053ec68
...
...
@@ -2,7 +2,6 @@ import { logger, Level } from "@coder/logger"
import
*
as
assert
from
"
assert
"
import
*
as
path
from
"
path
"
import
{
parse
}
from
"
../src/node/cli
"
import
{
paths
}
from
"
../src/node/util
"
describe
(
"
cli
"
,
()
=>
{
beforeEach
(()
=>
{
...
...
@@ -12,17 +11,15 @@ describe("cli", () => {
// The parser will always fill these out.
const
defaults
=
{
_
:
[],
"
extensions-dir
"
:
path
.
join
(
paths
.
data
,
"
extensions
"
),
"
user-data-dir
"
:
paths
.
data
,
}
it
(
"
should set defaults
"
,
async
()
=>
{
assert
.
deepEqual
(
await
await
parse
([]),
defaults
)
it
(
"
should set defaults
"
,
()
=>
{
assert
.
deepEqual
(
parse
([]),
defaults
)
})
it
(
"
should parse all available options
"
,
async
()
=>
{
it
(
"
should parse all available options
"
,
()
=>
{
assert
.
deepEqual
(
await
await
parse
([
parse
([
"
--bind-addr=192.169.0.1:8080
"
,
"
--auth
"
,
"
none
"
,
...
...
@@ -84,8 +81,8 @@ describe("cli", () => {
)
})
it
(
"
should work with short options
"
,
async
()
=>
{
assert
.
deepEqual
(
await
parse
([
"
-vvv
"
,
"
-v
"
]),
{
it
(
"
should work with short options
"
,
()
=>
{
assert
.
deepEqual
(
parse
([
"
-vvv
"
,
"
-v
"
]),
{
...
defaults
,
log
:
"
trace
"
,
verbose
:
true
,
...
...
@@ -95,17 +92,18 @@ describe("cli", () => {
assert
.
equal
(
logger
.
level
,
Level
.
Trace
)
})
it
(
"
should use log level env var
"
,
async
()
=>
{
it
(
"
should use log level env var
"
,
()
=>
{
process
.
env
.
LOG_LEVEL
=
"
debug
"
assert
.
deepEqual
(
await
parse
([]),
{
assert
.
deepEqual
(
parse
([]),
{
...
defaults
,
log
:
"
debug
"
,
verbose
:
false
,
})
assert
.
equal
(
process
.
env
.
LOG_LEVEL
,
"
debug
"
)
assert
.
equal
(
logger
.
level
,
Level
.
Debug
)
process
.
env
.
LOG_LEVEL
=
"
trace
"
assert
.
deepEqual
(
await
parse
([]),
{
assert
.
deepEqual
(
parse
([]),
{
...
defaults
,
log
:
"
trace
"
,
verbose
:
true
,
...
...
@@ -116,23 +114,25 @@ describe("cli", () => {
it
(
"
should prefer --log to env var and --verbose to --log
"
,
async
()
=>
{
process
.
env
.
LOG_LEVEL
=
"
debug
"
assert
.
deepEqual
(
await
parse
([
"
--log
"
,
"
info
"
]),
{
assert
.
deepEqual
(
parse
([
"
--log
"
,
"
info
"
]),
{
...
defaults
,
log
:
"
info
"
,
verbose
:
false
,
})
assert
.
equal
(
process
.
env
.
LOG_LEVEL
,
"
info
"
)
assert
.
equal
(
logger
.
level
,
Level
.
Info
)
process
.
env
.
LOG_LEVEL
=
"
trace
"
assert
.
deepEqual
(
await
parse
([
"
--log
"
,
"
info
"
]),
{
assert
.
deepEqual
(
parse
([
"
--log
"
,
"
info
"
]),
{
...
defaults
,
log
:
"
info
"
,
verbose
:
false
,
})
assert
.
equal
(
process
.
env
.
LOG_LEVEL
,
"
info
"
)
assert
.
equal
(
logger
.
level
,
Level
.
Info
)
process
.
env
.
LOG_LEVEL
=
"
warn
"
assert
.
deepEqual
(
await
parse
([
"
--log
"
,
"
info
"
,
"
--verbose
"
]),
{
assert
.
deepEqual
(
parse
([
"
--log
"
,
"
info
"
,
"
--verbose
"
]),
{
...
defaults
,
log
:
"
trace
"
,
verbose
:
true
,
...
...
@@ -141,34 +141,31 @@ describe("cli", () => {
assert
.
equal
(
logger
.
level
,
Level
.
Trace
)
})
it
(
"
should ignore invalid log level env var
"
,
async
()
=>
{
it
(
"
should ignore invalid log level env var
"
,
()
=>
{
process
.
env
.
LOG_LEVEL
=
"
bogus
"
assert
.
deepEqual
(
await
parse
([]),
defaults
)
assert
.
deepEqual
(
parse
([]),
defaults
)
})
it
(
"
should error if value isn't provided
"
,
async
()
=>
{
a
wait
assert
.
rejects
(
async
()
=>
await
parse
([
"
--auth
"
]),
/--auth requires a value/
)
a
wait
assert
.
rejects
(
async
()
=>
await
parse
([
"
--auth=
"
,
"
--log=debug
"
]),
/--auth requires a value/
)
a
wait
assert
.
rejects
(
async
()
=>
await
parse
([
"
--auth
"
,
"
--log
"
]),
/--auth requires a value/
)
a
wait
assert
.
rejects
(
async
()
=>
await
parse
([
"
--auth
"
,
"
--invalid
"
]),
/--auth requires a value/
)
a
wait
assert
.
rejects
(
async
()
=>
await
parse
([
"
--bind-addr
"
]),
/--bind-addr requires a value/
)
it
(
"
should error if value isn't provided
"
,
()
=>
{
a
ssert
.
throws
(()
=>
parse
([
"
--auth
"
]),
/--auth requires a value/
)
a
ssert
.
throws
(()
=>
parse
([
"
--auth=
"
,
"
--log=debug
"
]),
/--auth requires a value/
)
a
ssert
.
throws
(()
=>
parse
([
"
--auth
"
,
"
--log
"
]),
/--auth requires a value/
)
a
ssert
.
throws
(()
=>
parse
([
"
--auth
"
,
"
--invalid
"
]),
/--auth requires a value/
)
a
ssert
.
throws
(()
=>
parse
([
"
--bind-addr
"
]),
/--bind-addr requires a value/
)
})
it
(
"
should error if value is invalid
"
,
async
()
=>
{
await
assert
.
rejects
(
async
()
=>
await
parse
([
"
--port
"
,
"
foo
"
]),
/--port must be a number/
)
await
assert
.
rejects
(
async
()
=>
await
parse
([
"
--auth
"
,
"
invalid
"
]),
/--auth valid values:
\[
password, none
\]
/
)
await
assert
.
rejects
(
async
()
=>
await
parse
([
"
--log
"
,
"
invalid
"
]),
/--log valid values:
\[
trace, debug, info, warn, error
\]
/
,
)
it
(
"
should error if value is invalid
"
,
()
=>
{
assert
.
throws
(()
=>
parse
([
"
--port
"
,
"
foo
"
]),
/--port must be a number/
)
assert
.
throws
(()
=>
parse
([
"
--auth
"
,
"
invalid
"
]),
/--auth valid values:
\[
password, none
\]
/
)
assert
.
throws
(()
=>
parse
([
"
--log
"
,
"
invalid
"
]),
/--log valid values:
\[
trace, debug, info, warn, error
\]
/
)
})
it
(
"
should error if the option doesn't exist
"
,
async
()
=>
{
a
wait
assert
.
rejects
(
async
()
=>
await
parse
([
"
--foo
"
]),
/Unknown option --foo/
)
it
(
"
should error if the option doesn't exist
"
,
()
=>
{
a
ssert
.
throws
(()
=>
parse
([
"
--foo
"
]),
/Unknown option --foo/
)
})
it
(
"
should not error if the value is optional
"
,
async
()
=>
{
assert
.
deepEqual
(
await
parse
([
"
--cert
"
]),
{
it
(
"
should not error if the value is optional
"
,
()
=>
{
assert
.
deepEqual
(
parse
([
"
--cert
"
]),
{
...
defaults
,
cert
:
{
value
:
undefined
,
...
...
@@ -176,33 +173,30 @@ describe("cli", () => {
})
})
it
(
"
should not allow option-like values
"
,
async
()
=>
{
a
wait
assert
.
rejects
(
async
()
=>
await
parse
([
"
--socket
"
,
"
--socket-path-value
"
]),
/--socket requires a value/
)
it
(
"
should not allow option-like values
"
,
()
=>
{
a
ssert
.
throws
(()
=>
parse
([
"
--socket
"
,
"
--socket-path-value
"
]),
/--socket requires a value/
)
// If you actually had a path like this you would do this instead:
assert
.
deepEqual
(
await
parse
([
"
--socket
"
,
"
./--socket-path-value
"
]),
{
assert
.
deepEqual
(
parse
([
"
--socket
"
,
"
./--socket-path-value
"
]),
{
...
defaults
,
socket
:
path
.
resolve
(
"
--socket-path-value
"
),
})
await
assert
.
rejects
(
async
()
=>
await
parse
([
"
--cert
"
,
"
--socket-path-value
"
]),
/Unknown option --socket-path-value/
,
)
assert
.
throws
(()
=>
parse
([
"
--cert
"
,
"
--socket-path-value
"
]),
/Unknown option --socket-path-value/
)
})
it
(
"
should allow positional arguments before options
"
,
async
()
=>
{
assert
.
deepEqual
(
await
parse
([
"
foo
"
,
"
test
"
,
"
--auth
"
,
"
none
"
]),
{
it
(
"
should allow positional arguments before options
"
,
()
=>
{
assert
.
deepEqual
(
parse
([
"
foo
"
,
"
test
"
,
"
--auth
"
,
"
none
"
]),
{
...
defaults
,
_
:
[
"
foo
"
,
"
test
"
],
auth
:
"
none
"
,
})
})
it
(
"
should support repeatable flags
"
,
async
()
=>
{
assert
.
deepEqual
(
await
parse
([
"
--proxy-domain
"
,
"
*.coder.com
"
]),
{
it
(
"
should support repeatable flags
"
,
()
=>
{
assert
.
deepEqual
(
parse
([
"
--proxy-domain
"
,
"
*.coder.com
"
]),
{
...
defaults
,
"
proxy-domain
"
:
[
"
*.coder.com
"
],
})
assert
.
deepEqual
(
await
parse
([
"
--proxy-domain
"
,
"
*.coder.com
"
,
"
--proxy-domain
"
,
"
test.com
"
]),
{
assert
.
deepEqual
(
parse
([
"
--proxy-domain
"
,
"
*.coder.com
"
,
"
--proxy-domain
"
,
"
test.com
"
]),
{
...
defaults
,
"
proxy-domain
"
:
[
"
*.coder.com
"
,
"
test.com
"
],
})
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录