kingpin_parser.go
package kingpin_parser
import (
"strconv"
"gopkg.in/alecthomas/kingpin.v2"
"fmt"
)
type size uint64
//单位换算
func (s *size) Set(value string) error {
num, err := strconv.ParseUint(value[:len(value) - 1], 10, 64)
if err != nil {
return fmt.Errorf("can't parse \"%s\"", value)
}
switch value[len(value) - 1] {
case 'B', 'b':
case 'K', 'k':
num = num << 10
case 'M', 'm':
num = num << 20
case 'G', 'g':
num = num << 30
default:
return fmt.Errorf("can't parse \"%s\"", value)
}
*s = size(num)
return nil
}
//数据支持标准输出
func (s *size) String() string {
return strconv.FormatUint(uint64(*s), 10)
}
//字节大小设置
func Size(s kingpin.Settings) (target *uint64) {
target = new(uint64)
s.SetValue((*size)(target))
return
}
kingpin_parser.go的更多相关文章
随机推荐
- UML类图简介
概述 设计模式中常常使用UML来表示类与类,类与接口之间的关系,UML类图是设计模式入门必备的技能,感觉各种关系比较多,这里做一下总结. 类与接口的表示 类与接口通常是一个矩形框表示,一般分为3层,第 ...
- python MultiProcessing模块进程间通信的解惑与回顾
这段时间沉迷MultiProcessing模块不能自拔,没办法,python的基础不太熟,因此就是在不断地遇到问题解决问题.之前学习asyncio模块学的一知半解,后来想起MultiProcessin ...
- 手机访问pc地址时直接跳到移动端
function mobile_device_detect(url) { var thisOS = navigator.platform; var os = new Array("iPhon ...
- 类似Jquery ui 标签页(Tabs)
<div class="indexnew_tit"> <a href="javascript:;" class="on"& ...
- EF中关于TransactionScope的使用
前提条件 TransactionScope类需要引用System.Transactions; 数据库环境及需求 现在假设有两个表如图: ...
- Python循环依赖问题的解决
一个是把某个import移到代码中间,使原先的循环依赖圈打开.
- Ocelot中文文档-管理
Ocelot支持在运行时通过一个认证的Http API修改配置.有两种方式对其验证, 使用Ocelot的内置IdentityServer(仅用于向管理API验证请求)或将管理API验证挂接到您自己的I ...
- es6(五):class关键字(extends,super,static)
ES5中,生成对象通过构造函数: function A(name,age){ this.name=name; this.age=age } // 在A的prototype属性上定义一个test方法,即 ...
- gitlab钩子搭建
目标:在本地开发机上push代码到GitLab仓库时,通过钩子同步到测试服务器 准备工作GitLab 服务器一台测试服务器一台本地开发服务器一台 1.在gitlab上新建一个项目,名称test2.在本 ...
- seek()对中文偏移测试
当前目录下创建"中文测试.txt"文件,写入: 我是大好人aaa我是大坏人bbb f = open('中文测试.txt', 'r+', encoding='utf-8') # f. ...