forked from astaxie/gopkg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
139 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
返回值 | ||
|
||
功能说明 | ||
将命令行指定flag值绑定到一个bool变量 | ||
- 将指定flag值绑定到一个bool变量,底层实际调用了全局变量CommandLine的BoolVar函数 | ||
|
||
代码示例 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
返回值 | ||
|
||
功能说明 | ||
- 将f中指定flag参数值绑定到int变量 | ||
- 将f中指定flag参数值绑定到int64变量 | ||
|
||
代码示例 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
- error 设置成功返回nil | ||
|
||
功能说明 | ||
- 修改指定flag的值 | ||
- 修改指定flag的值,成功返回nil | ||
|
||
示例 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,5 +64,7 @@ | |
} | ||
|
||
运行结果 | ||
|
||
// ./testflagsetvar | ||
[1h1m0s 72h0m0s 1m20s] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
返回值 | ||
|
||
功能说明 | ||
- 将命令行指定flag参数值绑定到int64变量 | ||
- 将指定flag参数值绑定到int64变量 | ||
|
||
示例 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
返回值 | ||
|
||
功能说明 | ||
- 将所有已设置flag的默认值输出到标准输出,默认值包括默认值,默认错误提示等。 | ||
- 将所有已定义flag的默认值输出到标准错误,默认值包括默认值,默认错误提示等。 | ||
|
||
示例 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters