使用 go 开发 selpg 命令
前期准备
- 安装 pflag
1 | go get github.com/spf13/pflag |
- 测试是否安装成功
1 | $ go test github.com/spf13/pflag |
编码开始
- 引入相关包
1 | import ( |
- 定义数据结构
1 | type Selpg struct { |
- 判断文件是否为空
1 | if sp.inputFile != "" { |
- 文件分页
1 | currentPage := 1 |
测试
Case 1
1 | # test1.sh |
Input
1 | selpg --s 1 --e 1 test1 |
Output
1 | line 1 |
Case 2
1 | # test2.sh |
Input
1 | selpg --s 1 --e 3 test2 |
Output
1 | line 1 |
/