Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doodoocoder
prometheus
提交
8887f1e1
P
prometheus
项目概览
doodoocoder
/
prometheus
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
prometheus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8887f1e1
编写于
6月 25, 2015
作者:
J
Julius Volz
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #853 from prometheus/fabxc/help
cmd/prometheus: improve help output
上级
e701bdc4
52507041
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
47 addition
and
43 deletion
+47
-43
cmd/prometheus/config.go
cmd/prometheus/config.go
+47
-43
未找到文件。
cmd/prometheus/config.go
浏览文件 @
8887f1e1
...
...
@@ -18,9 +18,10 @@ import (
"fmt"
"net"
"os"
"sort"
"strings"
"text/template"
"time"
"unicode"
"github.com/prometheus/log"
"github.com/prometheus/prometheus/notification"
...
...
@@ -54,6 +55,9 @@ func init() {
cfg
.
fs
=
flag
.
CommandLine
// Set additional defaults.
cfg
.
storage
.
SyncStrategy
=
local
.
Adaptive
cfg
.
fs
.
BoolVar
(
&
cfg
.
printVersion
,
"version"
,
false
,
"Print version information."
,
...
...
@@ -209,9 +213,6 @@ func init() {
&
cfg
.
queryEngine
.
MaxConcurrentQueries
,
"query.max-concurrency"
,
20
,
"Maximum number of queries executed concurrently."
,
)
// Set additional defaults.
cfg
.
storage
.
SyncStrategy
=
local
.
Adaptive
}
func
parse
(
args
[]
string
)
error
{
...
...
@@ -245,10 +246,44 @@ func parse(args []string) error {
return
nil
}
var
helpTmpl
=
`
usage: prometheus [<args>]
{{ range $cat, $flags := . }}{{ if ne $cat "." }} == {{ $cat | upper }} =={{ end }}
{{ range $flags }}
-{{ .Name }} {{ .DefValue | quote }}
{{ .Usage | wrap 80 6 }}
{{ end }}
{{ end }}
`
func
usage
()
{
helpTmpl
=
strings
.
TrimSpace
(
helpTmpl
)
t
:=
template
.
New
(
"usage"
)
t
=
t
.
Funcs
(
template
.
FuncMap
{
"wrap"
:
func
(
width
,
indent
int
,
s
string
)
(
ns
string
)
{
width
=
width
-
indent
length
:=
indent
for
_
,
w
:=
range
strings
.
SplitAfter
(
s
,
" "
)
{
if
length
+
len
(
w
)
>
width
{
ns
+=
"
\n
"
+
strings
.
Repeat
(
" "
,
indent
)
length
=
0
}
ns
+=
w
length
+=
len
(
w
)
}
return
strings
.
TrimSpace
(
ns
)
},
"quote"
:
func
(
s
string
)
string
{
if
len
(
s
)
==
0
||
s
==
"false"
||
s
==
"true"
||
unicode
.
IsDigit
(
rune
(
s
[
0
]))
{
return
s
}
return
fmt
.
Sprintf
(
"%q"
,
s
)
},
"upper"
:
strings
.
ToUpper
,
})
t
=
template
.
Must
(
t
.
Parse
(
helpTmpl
))
groups
:=
make
(
map
[
string
][]
*
flag
.
Flag
)
// Set a default group for ungrouped flags.
groups
[
"."
]
=
make
([]
*
flag
.
Flag
,
0
)
// Bucket flags into groups based on the first of their dot-separated levels.
cfg
.
fs
.
VisitAll
(
func
(
fl
*
flag
.
Flag
)
{
...
...
@@ -260,43 +295,12 @@ func usage() {
groups
[
name
]
=
append
(
groups
[
name
],
fl
)
}
})
groupsOrdered
:=
make
(
sort
.
StringSlice
,
0
,
len
(
groups
))
for
groupName
:=
range
groups
{
groupsOrdered
=
append
(
groupsOrdered
,
groupName
)
}
sort
.
Sort
(
groupsOrdered
)
fmt
.
Fprintf
(
os
.
Stderr
,
"Usage: %s [options ...]:
\n\n
"
,
os
.
Args
[
0
])
const
(
maxLineLength
=
80
lineSep
=
"
\n
"
)
for
_
,
groupName
:=
range
groupsOrdered
{
if
groupName
!=
"."
{
fmt
.
Fprintf
(
os
.
Stderr
,
"
\n
%s:
\n
"
,
strings
.
Title
(
groupName
))
}
for
_
,
fl
:=
range
groups
[
groupName
]
{
format
:=
" -%s=%s"
if
strings
.
Contains
(
fl
.
DefValue
,
" "
)
||
fl
.
DefValue
==
""
{
format
=
" -%s=%q"
}
flagUsage
:=
fmt
.
Sprintf
(
format
+
lineSep
,
fl
.
Name
,
fl
.
DefValue
)
// Format the usage text to not exceed maxLineLength characters per line.
words
:=
strings
.
SplitAfter
(
fl
.
Usage
,
" "
)
lineLength
:=
len
(
lineSep
)
-
1
for
_
,
w
:=
range
words
{
if
lineLength
+
len
(
w
)
>
maxLineLength
{
flagUsage
+=
lineSep
lineLength
=
len
(
lineSep
)
-
1
}
flagUsage
+=
w
lineLength
+=
len
(
w
)
}
fmt
.
Fprintf
(
os
.
Stderr
,
"%s
\n
"
,
flagUsage
)
for
cat
,
fl
:=
range
groups
{
if
len
(
fl
)
<
2
&&
cat
!=
"."
{
groups
[
"."
]
=
append
(
groups
[
"."
],
fl
...
)
delete
(
groups
,
cat
)
}
}
t
.
Execute
(
os
.
Stdout
,
groups
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录