Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
d142a5e3
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d142a5e3
编写于
7月 07, 2016
作者:
D
Daniel Imms
提交者:
GitHub
7月 07, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #8845 from Microsoft/tyriar/cli_help_format
Tyriar/cli help format
上级
b66f2506
e3fcbe6b
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
83 addition
and
10 deletion
+83
-10
src/vs/code/node/argv.ts
src/vs/code/node/argv.ts
+40
-8
src/vs/code/node/cli.ts
src/vs/code/node/cli.ts
+2
-2
src/vs/code/test/node/argv.test.ts
src/vs/code/test/node/argv.test.ts
+41
-0
未找到文件。
src/vs/code/node/argv.ts
浏览文件 @
d142a5e3
...
...
@@ -5,7 +5,6 @@
import
*
as
os
from
'
os
'
;
import
*
as
minimist
from
'
minimist
'
;
import
pkg
from
'
vs/platform/package
'
;
import
{
localize
}
from
'
vs/nls
'
;
export
interface
ParsedArgs
extends
minimist
.
ParsedArgs
{
...
...
@@ -89,20 +88,53 @@ export const optionsHelp: { [name: string]: string; } = {
'
--verbose
'
:
localize
(
'
verbose
'
,
"
Print verbose output (implies --wait).
"
),
'
-w, --wait
'
:
localize
(
'
wait
'
,
"
Wait for the window to be closed before returning.
"
),
'
--list-extensions
'
:
localize
(
'
listExtensions
'
,
"
List the installed extensions.
"
),
'
--install-extension <ext
ension
>
'
:
localize
(
'
installExtension
'
,
"
Installs an extension.
"
),
'
--uninstall-extension <ext
ension
>
'
:
localize
(
'
uninstallExtension
'
,
"
Uninstalls an extension.
"
),
'
--install-extension <ext>
'
:
localize
(
'
installExtension
'
,
"
Installs an extension.
"
),
'
--uninstall-extension <ext>
'
:
localize
(
'
uninstallExtension
'
,
"
Uninstalls an extension.
"
),
'
-v, --version
'
:
localize
(
'
version
'
,
"
Print version.
"
),
'
-h, --help
'
:
localize
(
'
help
'
,
"
Print usage.
"
)
};
function
formatOptions
(
options
:
{
[
name
:
string
]:
string
;
}):
string
{
return
Object
.
keys
(
options
)
.
reduce
((
r
,
key
)
=>
r
.
concat
([
`
${
key
}
`
,
`
${
options
[
key
]
}
`
]),
[]).
join
(
'
\n
'
);
export
function
formatOptions
(
options
:
{
[
name
:
string
]:
string
;
},
columns
:
number
):
string
{
let
keys
=
Object
.
keys
(
options
);
let
argLength
=
Math
.
max
.
apply
(
null
,
keys
.
map
(
k
=>
k
.
length
))
+
2
/*left padding*/
+
1
/*right padding*/
;
if
(
columns
-
argLength
<
25
)
{
// Use a condensed version on narrow terminals
return
keys
.
reduce
((
r
,
key
)
=>
r
.
concat
([
`
${
key
}
`
,
`
${
options
[
key
]
}
`
]),
[]).
join
(
'
\n
'
);
}
let
descriptionColumns
=
columns
-
argLength
-
1
;
let
result
=
''
;
keys
.
forEach
(
k
=>
{
let
wrappedDescription
=
wrapText
(
options
[
k
],
descriptionColumns
);
let
keyPadding
=
(
<
any
>
'
'
).
repeat
(
argLength
-
k
.
length
-
2
/*left padding*/
);
if
(
result
.
length
>
0
)
{
result
+=
'
\n
'
;
}
result
+=
'
'
+
k
+
keyPadding
+
wrappedDescription
[
0
];
for
(
var
i
=
1
;
i
<
wrappedDescription
.
length
;
i
++
)
{
result
+=
'
\n
'
+
(
<
any
>
'
'
).
repeat
(
argLength
)
+
wrappedDescription
[
i
];
}
});
return
result
;
}
function
wrapText
(
text
:
string
,
columns
:
number
)
:
string
[]
{
let
lines
=
[];
while
(
text
.
length
)
{
let
index
=
text
.
length
<
columns
?
text
.
length
:
text
.
lastIndexOf
(
'
'
,
columns
);
let
line
=
text
.
slice
(
0
,
index
).
trim
();
text
=
text
.
slice
(
index
);
lines
.
push
(
line
);
}
return
lines
;
}
export
const
helpMessage
=
`Visual Studio Code v
${
pkg
.
version
}
export
function
buildHelpMessage
(
version
:
string
):
string
{
let
columns
=
(
<
any
>
process
.
stdout
).
isTTY
?
(
<
any
>
process
.
stdout
).
columns
:
80
;
return
`Visual Studio Code v
${
version
}
Usage:
${
executable
}
[arguments] [paths...]
Options:
${
formatOptions
(
optionsHelp
)}
`
;
\ No newline at end of file
${
formatOptions
(
optionsHelp
,
columns
)}
`
;
}
\ No newline at end of file
src/vs/code/node/cli.ts
浏览文件 @
d142a5e3
...
...
@@ -6,7 +6,7 @@
import
{
spawn
}
from
'
child_process
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
assign
}
from
'
vs/base/common/objects
'
;
import
{
parseArgs
,
h
elpMessage
,
ParsedArgs
}
from
'
vs/code/node/argv
'
;
import
{
parseArgs
,
buildH
elpMessage
,
ParsedArgs
}
from
'
vs/code/node/argv
'
;
import
pkg
from
'
vs/platform/package
'
;
function
shouldSpawnCliProcess
(
argv
:
ParsedArgs
):
boolean
{
...
...
@@ -21,7 +21,7 @@ export function main(args: string[]): TPromise<void> {
const
argv
=
parseArgs
(
args
);
if
(
argv
.
help
)
{
console
.
log
(
helpMessage
);
console
.
log
(
buildHelpMessage
(
pkg
.
version
)
);
}
else
if
(
argv
.
version
)
{
console
.
log
(
pkg
.
version
);
}
else
if
(
shouldSpawnCliProcess
(
argv
))
{
...
...
src/vs/code/test/node/argv.test.ts
0 → 100644
浏览文件 @
d142a5e3
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
assert
=
require
(
'
assert
'
);
import
{
formatOptions
}
from
'
vs/code/node/argv
'
;
suite
(
'
formatOptions
'
,
()
=>
{
test
(
'
Text should display small columns correctly
'
,
()
=>
{
assert
.
equal
(
formatOptions
({
'
foo
'
:
'
bar
'
},
80
),
'
foo bar
'
);
assert
.
equal
(
formatOptions
({
'
f
'
:
'
bar
'
,
'
fo
'
:
'
ba
'
,
'
foo
'
:
'
b
'
},
80
),
'
f bar
\n
'
+
'
fo ba
\n
'
+
'
foo b
'
);
});
test
(
'
Text should wrap
'
,
()
=>
{
assert
.
equal
(
formatOptions
({
'
foo
'
:
(
<
any
>
'
bar
'
).
repeat
(
9
)
},
40
),
'
foo bar bar bar bar bar bar bar bar
\n
'
+
'
bar
'
);
});
test
(
'
Text should revert to the condensed view when the terminal is too narrow
'
,
()
=>
{
assert
.
equal
(
formatOptions
({
'
foo
'
:
(
<
any
>
'
bar
'
).
repeat
(
9
)
},
30
),
'
foo
\n
'
+
'
bar bar bar bar bar bar bar bar bar
'
);
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录