Skip to content

Commit

Permalink
增加两个遗漏的方法,修正部分错误
Browse files Browse the repository at this point in the history
  • Loading branch information
faberliu committed Nov 10, 2014
1 parent a839f4d commit edec890
Show file tree
Hide file tree
Showing 22 changed files with 139 additions and 30 deletions.
2 changes: 1 addition & 1 deletion flag/Arg.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- string 第i+1个非flag命令行参数的值

功能说明
- 获取第i+1个非flag命令行参数的值,使用前需要先调用`flag.Parse()`解析flag
- 获取第i+1个非flag命令行参数的值,使用前需要先调用`flag.Parse()`解析flag,底层实际调用了全局变量CommandLine的Arg函数

代码示例1

Expand Down
2 changes: 1 addition & 1 deletion flag/Args.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- []string 非flag命令行参数集合

功能说明
- 获取非flag命令行参数集合,使用前需要先调用`flag.Parse`解析flag
- 获取非flag命令行参数集合,使用前需要先调用`flag.Parse`解析flag,底层实际调用了全局变量CommandLine的Args函数

代码示例1

Expand Down
4 changes: 2 additions & 2 deletions flag/Bool.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
参数列表
- name string 命令行flag名称
- value bool 默认值
- usage string 当设置命令行标签不合法时的提示语
- usage string 帮助信息

返回值
- *bool 返回一个bool类型的flag值的地址

功能说明
- 定义一个带默认值和提示语句的bool类型flag,返回flag对应值的地址
- 定义一个带默认值和提示语句的bool类型flag,返回flag对应值的地址,底层实际调用了全局变量CommandLine的Bool方法

代码示例

Expand Down
2 changes: 1 addition & 1 deletion flag/BoolVar.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
返回值

功能说明
将命令行指定flag值绑定到一个bool变量
- 将指定flag值绑定到一个bool变量,底层实际调用了全局变量CommandLine的BoolVar函数

代码示例

Expand Down
6 changes: 3 additions & 3 deletions flag/FlagSetFloat64Var.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@

代码输出

./testflagsetfloat64
float64Flag 2.718e+31
float64Var -12.78
// ./testflagsetfloat64
float64Flag 2.718e+31
float64Var -12.78
52 changes: 52 additions & 0 deletions flag/FlagSetInt64.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
## func (f *FlagSet) Int64(name string, value int64, usage string) *int64

参数列表
- name string flag名称
- value int64 变量默认值
- usage string 提示信息

返回值
- *int64 返回一个int64类型的变量的地址

功能说明
- 为flag集合f增加爱一个带默认值和提示语句的int64类型flag,返回flag对应变量值的地址

代码示例

package main

import (
"flag"
"fmt"
)

const (
defaultUsage = "help message"
)

var (
myFlagSet = flag.NewFlagSet("newflagset", flag.ExitOnError)
int64Flag = myFlagSet.Int64("int64Flag", 100, defaultUsage)
int64Var int64
)

func init() {
myFlagSet.Int64Var(&int64Var, "int64Var", 20, defaultUsage)
}

func main() {
args := []string{
"--int64Flag", "22",
"-int64Var", "-10",
"arg2",
}
myFlagSet.Parse(args)
fmt.Println("int64Flag", *int64Flag)
fmt.Println("int64Var", int64Var)
}

代码输出

// ./testflagsetint64
int64Flag 22
int64Var -10
55 changes: 55 additions & 0 deletions flag/FlagSetInt64Var.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
## func (f *FlagSet) Int64Var(p *int64, name string, value int64, usage string)

参数列表
- p *int64 需要与flag参数值绑定的变量地址
- name string flag名称
- value int 变量默认值
- usage string 提示信息

返回值

功能说明
- 将f中指定flag参数值绑定到int64变量

功能说明
- 为flag集合f增加爱一个带默认值和提示语句的int64类型flag,返回flag对应变量值的地址

代码示例

package main

import (
"flag"
"fmt"
)

const (
defaultUsage = "help message"
)

var (
myFlagSet = flag.NewFlagSet("newflagset", flag.ExitOnError)
int64Flag = myFlagSet.Int64("int64Flag", 100, defaultUsage)
int64Var int64
)

func init() {
myFlagSet.Int64Var(&int64Var, "int64Var", 20, defaultUsage)
}

func main() {
args := []string{
"--int64Flag", "22",
"-int64Var", "-10",
"arg2",
}
myFlagSet.Parse(args)
fmt.Println("int64Flag", *int64Flag)
fmt.Println("int64Var", int64Var)
}

代码输出

// ./testflagsetint64
int64Flag 22
int64Var -10
2 changes: 1 addition & 1 deletion flag/FlagSetIntVar.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
返回值

功能说明
- 将f中指定flag参数值绑定到int变量
- 将f中指定flag参数值绑定到int64变量

代码示例

Expand Down
2 changes: 1 addition & 1 deletion flag/FlagSetNArg.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- int 返回解析后剩余的参数的数量

功能说明
- 获取输入参数解析后剩余的参数的数量,即fmt.Args()返回的值的元素个数
- 获取输入参数解析后剩余的参数的数量,即f.Args()返回的值的元素个数

示例

Expand Down
2 changes: 1 addition & 1 deletion flag/FlagSetParse.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
返回值

功能说明
- 从argumets中依次解析flag在定义flag之后,必须调用用本函数才能成功获取arguments中设置的flag的值
- 从argumets中依次解析flag.在定义flag之后,必须调用用本函数才能成功获取arguments中设置的flag的值

示例

Expand Down
4 changes: 2 additions & 2 deletions flag/FlagSetParsed.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
参数列表

返回值
- bool 若flag已解析,返回true
- bool 若flag设置参数已解析(已调用f.Parse()方法),返回true

功能说明
- 判断flag是否已经解析,若已解析返回true
- 判断flag设置参数是否已经解析(是否已调用f.Parse()方法),若已解析返回true

示例

Expand Down
2 changes: 1 addition & 1 deletion flag/FlagSetSet.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- error 设置成功返回nil

功能说明
- 修改指定flag的值
- 修改指定flag的值,成功返回nil

示例

Expand Down
2 changes: 2 additions & 0 deletions flag/FlagSetVar.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,7 @@
}

运行结果

// ./testflagsetvar
[1h1m0s 72h0m0s 1m20s]

2 changes: 1 addition & 1 deletion flag/Int64Var.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
返回值

功能说明
- 将命令行指定flag参数值绑定到int64变量
- 将指定flag参数值绑定到int64变量

示例

Expand Down
4 changes: 2 additions & 2 deletions flag/NArg.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
## func func NArg() int
## func NArg() int

参数列表

返回值
- int 返回解析后剩余的参数的数量

功能说明
- 获取命令行参数解析后剩余的参数的数量,即fmt.Args()返回的值的元素个数
- 获取命令行参数解析后剩余的参数的数量,即flag.Args()返回的值的元素个数

示例

Expand Down
2 changes: 1 addition & 1 deletion flag/Parse.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
返回值

功能说明
- 从os.Args[1:]中依次解析flag在定义flag之后,必须调用用本函数才能成功获取命令行flag的值
- 从os.Args[1:]中依次解析flag.在定义flag之后,必须调用用本函数才能成功获取命令行flag的值

示例

Expand Down
4 changes: 2 additions & 2 deletions flag/Parsed.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
参数列表

返回值
- 若命令行flag已解析,返回true
- 若命令行flag参数已解析(已调用flag.Parse()方法),返回true

功能说明
- 判断命令行flag是否已经解析,若已解析返回true
- 判断命令行flag参数是否已经解析(即调用flag.Parse()方法),若已解析返回true

示例

Expand Down
2 changes: 1 addition & 1 deletion flag/PrintDefaults.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
返回值

功能说明
- 将所有已设置flag的默认值输出到标准输出,默认值包括默认值,默认错误提示等。
- 将所有已定义flag的默认值输出到标准错误,默认值包括默认值,默认错误提示等。

示例

Expand Down
8 changes: 4 additions & 4 deletions flag/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ flag包提供了一系列解析命令行参数的功能接口
- [func PrintDefaults()](PrintDefaults.md)
- [func Set(name, value string) error](Set.md)
- [func String(name string, value string, usage string) *string](String.md)
- [func StringVar(p *string, name string, value string, usage string)](StringVar)
- [func StringVar(p *string, name string, value string, usage string)](StringVar.md)
- [func Uint(name string, value uint, usage string) *uint](Uint.md)
- [func Uint64(name string, value uint64, usage string) *uint64](Uint64.md)
- [func Uint64Var(p *uint64, name string, value uint64, usage string)](Uint64Var.md)
Expand Down Expand Up @@ -73,9 +73,9 @@ flag包提供了一系列解析命令行参数的功能接口
- [func (f *FlagSet) Init(name string, errorHandling ErrorHandling)](FlagSetInit.md)
- [func (f *FlagSet) Int(name string, value int, usage string) *int](FlagSetInt.md)
- [func (f *FlagSet) Int64(name string, value int64, usage string) *int64](FlagSetInt64.md)
- [func (f *FlagSet) Int64Var(p *int64, name string, value int64, usage string)](FlagSetInt64Var)
- [func (f *FlagSet) IntVar(p *int, name string, value int, usage string)](FlagSetIntVar)
- [func (f *FlagSet) Lookup(name string) *Flag](FlagSetIntVar.md)
- [func (f *FlagSet) Int64Var(p *int64, name string, value int64, usage string)](FlagSetInt64Var.md)
- [func (f *FlagSet) IntVar(p *int, name string, value int, usage string)](FlagSetIntVar.md)
- [func (f *FlagSet) Lookup(name string) *Flag](FlagSetLookup.md)
- [func (f *FlagSet) NArg() int](FlagSetNArg.md)
- [func (f *FlagSet) NFlag() int](FlagSetNFlag.md)
- [func (f *FlagSet) Parse(arguments []string) error](FlagSetParse.md)
Expand Down
6 changes: 3 additions & 3 deletions flag/Set.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
## func Set(name, value string) error

参数列表
- name string
- value string
- name string flag 名称
- value string flag 值

返回值
- error 设置成功返回nil

功能说明
- 将名称为name的flag的值设置为value, name必须存在
- 将名称为name的flag的值设置为value, 成功返回nil

示例

Expand Down
2 changes: 1 addition & 1 deletion flag/Visit.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
返回值

功能说明
- 按照字典顺序遍历所有命令行已设置的flag参数,对每个参数调用fn方法
- 按照字典顺序遍历所有命令行已设置的flag参数(只定义了但未在命令行被设置的flag不会被遍历),对每个参数调用fn方法

代码示例

Expand Down
2 changes: 1 addition & 1 deletion flag/VisitAll.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
返回值

功能说明
- 按照字典顺序遍历所有已设置的flag参数(不管是否在命令行中设置),对每个参数调用fn方法
- 按照字典顺序遍历所有已定义的flag参数(不管是否在命令行中设置),对每个参数调用fn方法

代码示例

Expand Down

0 comments on commit edec890

Please sign in to comment.